美文网首页
iOS 导航栏 navigationItem.titleView

iOS 导航栏 navigationItem.titleView

作者: Mr_zhangjin | 来源:发表于2021-06-25 12:14 被阅读0次

方法一:

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

      本文链接:https://www.haomeiwen.com/subject/cbznyltx.html