简体   繁体   中英

iOS - ScopeBar overlaps SearchBar in UISearchController in TabBarController

I am running into a peculiar issue regarding a scope bar shown under my UISearchBar. Basically, the issue I previously had was that whenever my UISearchController was active and the user switched tabs, if he came back to the UIViewController containing the UISearchController, the background would turn back. This issue was solved by embedding the UIViewController into a UINavigationController.

Now, a new issue has appeared. When I switch tabs with the UISearchController already active, when I switch back, the UIScopeBar is displayed on top of the UISearchBar. This can only be fixed by Canceling the search, and starting over.

Illustration: 在此处输入图片说明

I have tried hiding the following code:

-(void)viewWillAppear:(BOOL)animated{
if(self.searchController.isActive){
    [self.searchController.searchBar setShowsScopeBar:TRUE];
}
}

-(void)viewDidDisappear:(BOOL)animated{
    if(self.searchController.isActive){
        [self.searchController.searchBar setShowsScopeBar:FALSE];
    }
}

To no avail. If anybody has a trick for this one, I'd be glad to try it out.

Setting a constraint programatically each time you generate the view and come back to that tab might do the trick by keeping the UIScopeBar at a fixed distance from the top. You can also try setting the contraint between UIScopeBar and UISearchBar.

NSLayoutConstraint *topSpaceConstraint = [NSLayoutConstraint constraintWithItem:self.view
                                                                             attribute:NSLayoutAttributeTop
                                                                             relatedBy:NSLayoutRelationEqual
                                                                                toItem:UIScopeBar 
                                                                             attribute:NSLayoutAttributeTop
                                                                            multiplier:1.0
                                                                              constant:5.0];
[self.view addConstraint:topSpaceConstraint];

If this does not do the trick, you'll need to provide more code for me/people here to replicate the bug you're having.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM