xcode 调整 UISearchDisplayController 变暗的黑色覆盖

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7989273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:19:15  来源:igfitidea点击:

resize UISearchDisplayController dimmed black overlay

iphoneiosxcodeuisearchbaruisearchdisplaycontroller

提问by Desmond

anybody know how to resize the dimmed black overly, once you clicked the search bar ?

单击搜索栏后,有人知道如何过度调整变暗的黑色吗?

i having problem when i clicked cancelled the tableview will expend then animated to disappear.

我在单击取消时遇到问题,tableview 将消耗然后动画消失。

i using this to resize my result 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];   
}

when clicked on the search bar, gray overlay are full instead of my defined size.

单击搜索栏时,灰色覆盖已满,而不是我定义的大小。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

when clicked cancel button, the view will expend back. enter image description here

当单击取消按钮时,视图将返回。 在此处输入图片说明

回答by tomeron11

I combined several answers in order to move the dimmed overlay frame.

我结合了几个答案以移动变暗的覆盖框。

1: override UISearchDisplayController class

1:覆盖 UISearchDisplayController 类

@interface MySearchController : UISearchDisplayController

2: override setActive function

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: change the xib/storyboard Search Display Controller from UISearchDisplayController to MySearchController

3:将xib/storyboard Search Display Controller从UISearchDisplayController改为MySearchController

回答by Wolfert

I thought the searchDisplayController owned a seperate tableview, so my guess is that you would need to resize that one.

我认为 searchDisplayController 拥有一个单独的 tableview,所以我的猜测是你需要调整它的大小。

Something along the lines of: <yourSearchViewController>.view.frame =self.tableView.frame;

类似的东西: <yourSearchViewController>.view.frame =self.tableView.frame;

or if you don't have it as class variable, in a method which receives it as argument, eg:

或者,如果您没有将其作为类变量,则在将其作为参数接收的方法中,例如:

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

Alternativily you might want to subclass it and override its view properties locally.

或者,您可能希望子类化它并在本地覆盖其视图属性。

Hope this helps!

希望这可以帮助!

回答by thesummersign

The UISearchDisplayControllerdoes owns its own tableview which not as easy to tame. I came across something like this and am still looking for a better solution.

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

The above code does sets the background to transparent but seems to silently ignore the frame size.

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

EDIT:SOLVEDI found the robust solution to this here. This saved my life.

编辑:解决了我在这里找到了强大的解决方案。这救了我的命。