1

I've a UISearchController in FirstViewController's navigationItem. And the same in a SecondViewController and I push SecondViewController from FirstViewController.

When the user slides to go back, the below UI glitch is visible.

UISearchController glitch while sliding back

The area containing the UISearchController becomes dim. If the user goes back to FirstViewController, it looks good. But if the user stays in the SecondViewController after sliding a little, then this is what it looks like.

Missing UISearchController in navigationItem

The space which had the searchController is now empty. If the user scrolls up or down, the searchController becomes visible again.

Options tried to fix the issues

  • using UITableViewController instead of UIViewController with UITableView
  • toggling navigationItem.hidesSearchBarWhenScrolling property in viewDidLoad and viewWillAppear
  • setting navigationItem.searchController as nil in viewWillDisappear

Apart from this issue, when I use UITableView inside a UIViewController, the searchController hides under the title and comes out at a slightly high speed than the native apps like Messages, Mail. And when I use UITableViewController, the animation is smooth but the searchController gets struck halfway if the user does not slide up or down fully, like shown below. This happens both with and without large titles.

UISearchController getting struck

My usecase can also be achieved, if someone can answer this question.

UPDATE: setting extendedLayoutIncludesOpaqueBars as true in SecondViewController did resolve the issue. But there is a slight unwanted jerk in the tableview, if the user slides to go back but then changes his/her mind.

enter image description here

imthath
  • 1,353
  • 1
  • 13
  • 35

1 Answers1

0

Please try this.. It's working for me. I hope it's working for you too.

Objective-C

-(void)viewWillDisappear:(BOOL)animated{
    if (@available(iOS 13.0, *)) {
        [self.navigationController.view setNeedsLayout]; 
        [self.navigationController.view layoutIfNeeded];
    }
}

Swift

func viewWillDisappear(_ animated: Bool) {
    if (@available(iOS 13.0, *)) {
         self.navigationController?.view.setNeedsLayout()     
         self.navigationController?.view.layoutIfNeeded()
    }
}

if it not working then set animation NO or false when you push or present ViewController

Yogesh Patel
  • 1,893
  • 1
  • 20
  • 55
  • this worked to an extent but not fully. the spacing where the glitch occurred got reduced, but still it was slightly visible. and, setting an animation to false is not even an option in our app, that will give inconsistent user experience. – imthath Oct 30 '19 at 04:10