iOS swift 總結NavigationController出現問題及解決方案_IOS

來源:互聯網
上載者:User

IOS swift 總結NavigationController出現問題及解決方案

最近用Swift語言做了一些iOS項目,頗有些心得,記下一些深刻的問題造福自己,服務大家

1.以NavigationController做為容器後狀態列的字型顏色就會不在受系統的控制,要在NavigationController中的根ViewController中設定方可生效,代碼如下:

self.navigationController!.navigationBar.barStyle = UIBarStyle.Black

供選擇的有UIBarStyle.Black,UIBarStyle.Default,UIBarStyle.BlackOpaque,UIBarStyle.BlackTranslucent,具體選擇視項目需求而定

2.NavigationController做為容器後內建的滑動返回效果失效問題

導致該問題的情況是在storyboard中push到下一個頁面後會自動產生一個navigationItem做為導覽列,當我們自己拖個按鈕到導覽列返回按鈕的位置,

並自訂了返回事件後,滑動返回效果就會失效

解決方案如下:

NavigationController的根ViewController繼承UIGestureRecognizerDelegate,viewDidLoad()中添加

self.navigationController!.interactivePopGestureRecognizer!.delegate = self

複寫方法gestureRecognizerShouldBegin()代碼如下:

 func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {    if (self.navigationController!.viewControllers.count == 1){      return false    }else{     return true    }  }

感謝閱讀,希望能協助到大家,謝謝大家對本站的支援!

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.