resize UISearchDisplayController dimmed black overlay

后端 未结 3 876
梦毁少年i
梦毁少年i 2021-02-04 17:16

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 t

相关标签:
3条回答
  • 2021-02-04 17:34

    The UISearchDisplayController does owns its own tableview which not as easy to tame. I came across something like this and am still looking for a better 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 does sets the background to transparent but seems to silently ignore the frame size.

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

    0 讨论(0)
  • 2021-02-04 17:39

    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

    0 讨论(0)
  • 2021-02-04 17:42

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

    Something along the lines of: <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!

    0 讨论(0)
提交回复
热议问题