Resize UISearchDisplayController Dimming Black Overlay

Does anyone know how to resize a darkened black as soon as you click on the search bar?

I have a problem when I clicked, canceled the tableview, and then it will animate to disappear.

i using this to resize the result table.

-(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 I click on the search bar, the gray overlay is filled in place of my specific size.

enter image description here

enter image description here

when you click cancel, the view will return. enter image description here

+7
source share
3 answers

I combined several answers to move the darkened overlay frame.

1: override the UISearchDisplayController class

 @interface MySearchController : UISearchDisplayController 

2: override setActive function

 - (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 display / storyboard display controller from UISearchDisplayController to MySearchController

+10
source

I thought searchDisplayController has a separate table, so I assume that you will need to resize it.

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

or if you do not have it as a class variable, in a method that receives it as an argument, for example:

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

Alternatively, you may want to subclass it and change its view properties locally.

Hope this helps!

+1
source

UISearchDisplayController has its own tabular view, which is not so easy to tame. I came across something similar, and I'm still looking for the best solution.

 -(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 makes the background transparent, but seems to silently ignore the frame size.

EDIT: solvable I found a reliable solution for this here . It saved my life.

0
source

All Articles