Thursday, February 1, 2018

iOS - ScopeBar overlaps SearchBar in UISearchController in TabBarController

Leave a Comment

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: enter image description here

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.

1 Answers

Answers 1

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.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment