uicollectionview教學 - swift4 uicollectionview



在Swift 4,iOS 11的UICollectionView中添加導航欄 (1)

請檢查 :

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

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

我將導航欄高度設置為“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)
    }

不過,我嘗試了這個代碼。 沒有什麼對我有用。


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