iOS 导航栏 navigationItem.titleView

2021-06-25  本文已影响0人  Mr_zhangjin

方法一:

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

    }

方法二解决了我的问题

上一篇 下一篇

猜你喜欢

热点阅读