1

升級iOS 11和Swift 4(Xcode 9)後,我遇到了很多UI問題。 :(
最無法解決的問題是導航問題。
把導航欄UICollectionView控制器
導航欄高度不正確顯示和但是我寫的代碼。
在UICollectionView中添加導航欄在iOS 4中,iOS 11

我設置導航欄的高度「 100" 。我寫這篇文章的代碼viewDidLoad中()。

if #available(iOS 11.0, *) { 

     print("IOS 11 Screen") 

     UINavigationBar.appearance().largeTitleTextAttributes = [ 
      NSForegroundColorAttributeName: UIColor.white, 

     ] 
     navigationItem.largeTitleDisplayMode = .never 
     let height: CGFloat = 100 //whatever height you want 
     let bounds = self.navigationController!.navigationBar.bounds 
     self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height) 


    } else { 
     print("lower than IOS 11 Screen") 
     // Fallback on earlier versions 
    } 

collectionview?.frame = CGRect(x: 0, y: 10, width: UIScreen.main.bounds.width, height: (UIScreen.main.bounds.height + 20)) <br> 

override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 
    let height: CGFloat = 100 //whatever height you want 
    let bounds = self.navigationController!.navigationBar.bounds 
    self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height) 

} 


override func viewWillAppear(_ animated: Bool) { 
     let height: CGFloat = 100 //whatever height you want 
     let bounds = self.navigationController!.navigationBar.bounds 
     self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height) 
    } 

不過,我試着用這個代碼。沒有爲我工作。

enter image description here


我還試圖打開源代碼視圖故事板,我編輯導航欄的高度。但是,這也行不通。
任何人都可以幫助我嗎?自過去兩天以來,我一直試圖解決這個問題。

+0

我不認爲你可以調整導航欄的高度。相反,您可以創建一個自定義導航欄,同時覆蓋系統給出的導航欄。 – antonio081014

回答

0

請檢查:

override func viewDidLoad() { 
    if #available(iOS 11.0, *) { 
     print("IOS 11 Screen") 
     UINavigationBar.appearance().largeTitleTextAttributes = [ 
      NSForegroundColorAttributeName: UIColor.white, 
     ] 
     self.navigationController?.navigationBar.prefersLargeTitles = true // added this line 
     navigationItem.largeTitleDisplayMode = .never 
    } else { 
     print("lower than IOS 11 Screen") 
     // Fallback on earlier versions 
    } 
} 

override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 
    let height: CGFloat = 100 //whatever height you want 
    let bounds = self.navigationController!.navigationBar.bounds 
    self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height) 
} 
+0

我現在可以解決這個問題。但我有另一個問題https://stackoverflow.com/questions/46376475/uinavigationbar-does-not-overlap-to-uicollectionview-in-swift-4你能幫我兄弟嗎? –

+0

你的解決方案是什麼? @MayPhyu – antonio081014

+0

@ antonio081014,我參考這個鏈接https://stackoverflow.com/questions/31940352/how-to-increase-the-height-of-navigation-bar-in-xcode。我增加空間來增加導航欄bro –