调整大小UISearchDisplayController灰色黑色叠加层

时间:2011-11-03 01:17:17

标签: iphone ios xcode uisearchbar uisearchdisplaycontroller

任何人都知道如果你点击搜索栏后如何过度调整暗灰色的大小?

我点击时遇到问题取消了tableview将耗费然后动画消失。

我用它来调整结果表视图的大小。

-(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];   
}

点击搜索栏时,灰色叠加层已满,而不是我定义的尺寸。

enter image description here

enter image description here

单击取消按钮时,视图将重新开始。 enter image description here

3 个答案:

答案 0 :(得分:10)

我合并了几个答案,以便移动调暗的叠加帧。

1:覆盖UISearchDisplayController类

@interface MySearchController : UISearchDisplayController

2:覆盖setActive函数

- (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 / storyboard搜索显示控制器从UISearchDisplayController更改为 MySearchController

答案 1 :(得分:1)

我认为searchDisplayController拥有一个单独的tableview,所以我猜你需要调整那个。{/ p>

以下内容:<yourSearchViewController>.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];   
}

另外,您可能希望将其子类化并在本地覆盖其视图属性。

希望这有帮助!

答案 2 :(得分:0)

UISearchDisplayController确实拥有自己的桌面视图,这不容易驯服。 我遇到过这样的事情,我仍在寻找更好的解决方案。

-(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];
}

上面的代码确实将背景设置为透明,但似乎默默地忽略了帧大小。

修改:解决 我找到了这个here的强大解决方案。 这拯救了我的生命。