iOS 导航栏 navigationItem.titleView = self.searchController.searchBar时 导航栏高度变高导致跳转时其他页面会有下移,返回也有移动的问题

方法一:

swift: 

searchBar.heightAnchor.constraint(equalToConstant: 44).isActive = true

oc:

[searchBar.heightAnchor constraintEqualToConstant:44].active = YES;

方法二:

在Stack Overflow上找到了答案

override func viewWillAppear(_ animated: Bool) {

        super.viewWillAppear(animated)

        navigationController?.view.setNeedsLayout() // force update layout

        navigationController?.view.layoutIfNeeded() // to fix height of the navigation bar

    }

    override func viewWillDisappear(_ animated: Bool) {

        super.viewWillDisappear(animated)

        navigationController?.view.setNeedsLayout() // force update layout

        navigationController?.view.layoutIfNeeded() // to fix height of the navigation bar

    }

方法二解决了我的问题

你可能感兴趣的:(iOS 导航栏 navigationItem.titleView = self.searchController.searchBar时 导航栏高度变高导致跳转时其他页面会有下移,返回也有移动的问题)