resize UISearchDisplayController dimmed black overlay

Desmond picture Desmond · Nov 3, 2011 · Viewed 7.6k times · Source

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.

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

Answer

tomeron11 picture tomeron11 · Nov 13, 2013

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

1: override 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/storyboard Search Display Controller from UISearchDisplayController to MySearchController