【问题标题】:iOS - Navigation bar does not show large titles when orientation changediOS - 方向更改时导航栏不显示大标题
【发布时间】:2019-07-24 15:58:40
【问题描述】:

我的导航栏上有 largeTitle 显示正确。

当我将设备方向更改为横向并返回纵向时,它会变为常规而不是 largeTitle。

这是一个标签栏控制器。当我切换选项卡(如下 gif 中的日历)时,视图会重新加载并正确显示

在我的标签栏控制器中,我添加了这个,但没有帮助我重新调整导航栏中的 largeTitle

override func viewWillTransition(to size: CGSize, with coordinator: 
  UIViewControllerTransitionCoordinator) {
          if UIDevice.current.orientation.isLandscape {
             //do something
          } else {

  self.navigationController?.navigationBar.prefersLargeTitles = true
              self.navigationItem.largeTitleDisplayMode = .always
          }
      }

如果我在我的 tabviewcontroller 中添加上面的代码,它甚至不会调用。它从我的标签栏控制器调用,但没有将标题更新为大标题

我在这里感到震惊。请告诉我如何解决这个问题

谢谢

【问题讨论】:

    标签: ios uinavigationbar uinavigationitem


    【解决方案1】:

    您可以在更改设备方向时将导航栏高度重置为默认值(为简单起见,我重置了整个导航栏框架):

    class ViewController: UIViewController {
    
        lazy var navigationControllerLargeTitleFrame: CGRect = {
            let navigationController = UINavigationController()
            navigationController.navigationBar.prefersLargeTitles = true
            return navigationController.navigationBar.frame
        }()
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            NotificationCenter.default.addObserver(self, selector: #selector(orientationDidChangeNotification), name: UIDevice.orientationDidChangeNotification, object: nil)
        }
    
        @objc func orientationDidChangeNotification(_ notification: NSNotification) {
            if UIDevice.current.orientation == .portrait {
                navigationController?.navigationBar.frame = navigationControllerLargeTitleFrame
            }
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 2018-03-04
      • 2020-03-14
      • 2020-03-08
      • 1970-01-01
      相关资源
      最近更新 更多