UISearchBar increases navigation bar height in iOS 11

后端 未结 19 1548
醉酒成梦
醉酒成梦 2020-11-28 02:47

I have my UISearchBar being part of the navigation bar like:

 let searchBar = UISearchBar()
 //some more configuration to the search bar
 .....
         


        
19条回答
  •  难免孤独
    2020-11-28 03:10

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

    • when i pushed another ViewControllers from ViewController with UISearchBar

    • when i dismissed ViewController with UISearchBar with "drag right to dismiss"

    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
    }
    

提交回复
热议问题