UISearchBar increases navigation bar height in iOS 11

I got black line under NavigationBar with SearchBar in iOS 11 in two cases:

  • when i pushed another ViewControllers from ViewController with UISearchBar
    enter image description here

  • when i dismissed ViewController with UISearchBar with “drag right to dismiss”
    enter image description here

My solution was: adding this code to my ViewController with UISearchBar:

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.view setNeedsLayout]; // force update layout
    [self.navigationController.view layoutIfNeeded]; // to fix height of the navigation bar
}

Swift 4 Update

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    navigationController?.view.setNeedsLayout() // force update layout
    navigationController?.view.layoutIfNeeded() // to fix height of the navigation bar
}

Leave a Comment