簡體   English   中英

iOS-方向改變時導航欄不顯示大標題

[英]iOS - Navigation bar does not show large titles when orientation changed

我的導航欄上有largeTitle,可以正確顯示。

當我將設備方向更改為橫向並改回縱向時,它變為常規而不是largeTitle。

這是一個標簽欄控制器。 當我切換標簽頁(如gif中的“日歷”)后,該視圖會重新加載並正確顯示

在我的標簽欄控制器中,我添加了此內容,但並沒有幫助我重新調整導航欄中的大標題

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中添加以上代碼,它甚至不會調用。 它從我的標簽欄控制器中調用,但沒有將標題更新為大

我被打中了。 請讓我知道我該如何解決

謝謝 在此處輸入圖片說明

您可以在更改設備方向時將導航欄高度重置為默認高度(為簡單起見,在這里我重置了整個導航欄框架):

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
        }
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM