Iphone 调整UISearchDisplayController暗显黑色覆盖的大小
一旦你点击搜索栏,有人知道如何调整暗黑色的大小吗 我有问题,当我点击取消表视图将花费然后动画消失 我使用它来调整结果表视图的大小Iphone 调整UISearchDisplayController暗显黑色覆盖的大小,iphone,ios,xcode,uisearchbar,uisearchdisplaycontroller,Iphone,Ios,Xcode,Uisearchbar,Uisearchdisplaycontroller,一旦你点击搜索栏,有人知道如何调整暗黑色的大小吗 我有问题,当我点击取消表视图将花费然后动画消失 我使用它来调整结果表视图的大小 -(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView { tableView.frame =fTableView.frame;//CGRectMake(26, 100
-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
tableView.frame =fTableView.frame;//CGRectMake(26, 100, 280, 310); //fTableView.frame;
tableView.backgroundColor = [UIColor colorWithRed:243.0/255.0 green:236.0/255.0 blue:212.0/255.0 alpha:1];
}
单击搜索栏时,灰色覆盖已满,而不是我定义的大小
单击“取消”按钮时,视图将向后扩展。
我认为searchDisplayController拥有一个单独的tableview,所以我猜您需要调整该tableview的大小 大致如下:
.view.frame=self.tableView.frame代码>
或者,如果没有将其作为类变量,则在将其作为参数接收的方法中,例如:
-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
controller.view.frame = self.tableView.frame;
tableView.backgroundColor = [UIColor colorWithRed:243.0/255.0 green:236.0/255.0 blue:212.0/255.0 alpha:1];
}
或者,您可能希望对其进行子类化,并在本地重写其视图属性
希望这有帮助 UISearchDisplayController
拥有自己的tableview,不容易驯服。
我遇到了这样的事情,仍然在寻找更好的解决方案
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
[controller.searchResultsTableView setDelegate:self];
CGFloat gr = 12.0;
controller.searchResultsTableView.backgroundColor = [UIColor colorWithRed:gr green:gr blue:gr alpha:0.0];
[controller.searchResultsTableView setSeparatorStyle:UITableViewCellSelectionStyleNone];
CGRect searchTableFrame = CGRectMake(7, 105, 305, 292);
[controller.searchResultsTableView setFrame:searchTableFrame];
}
上面的代码确实将背景设置为透明,但似乎忽略了帧大小
编辑:已解决
我找到了这个问题的可靠解决方案。
这救了我的命。为了移动暗淡的覆盖框,我综合了几个答案 1:重写UISearchDisplayController类
@interface MySearchController : UISearchDisplayController
2:覆盖设置激活功能
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
[super setActive: visible animated: animated];
//move the dimming part down
for (UIView *subview in self.searchContentsController.view.subviews) {
//NSLog(@"%@", NSStringFromClass([subview class]));
if ([subview isKindOfClass:NSClassFromString(@"UISearchDisplayControllerContainerView")])
{
CGRect frame = subview.frame;
frame.origin.y += 10;
subview.frame = frame;
}
}
}
3:将xib/情节提要搜索显示控制器从UISearchDisplayController更改为
MySearchController在
UISearchDisplayController
中没有类似的视图。您的解决方案给出了一个错误。这表明您应该查找什么。如果您再花几分钟时间查看控制器属性,您会注意到它确实有一个名为“searchResultsTableView”的特定视图。资料来源:我查看了控制器的.h
文件,发现了一个UIView*\u view
但它似乎没有暴露。“你应该试试这个,因为这可能行得通,如果不行,那么试试这个其他东西”更多的是一个注释,而不是一个答案“你可以做x,或者如果你想正确地做,你可以做y。”给op两个选项。我不完全同意你的意见,但感谢你的反馈。我还使用了自定义单元格模拟外观,好像它适合所需的宽度。Tom Swift的回答解决了我的问题:这是解决此问题的最佳解决方案。谢谢应用商店是否批准它进行黑客攻击?