iOS swift Summarizes the problems and solutions of NavigationController

  • 2021-08-12 03:49:16
  • OfStack

IOS swift summarizes the problems and solutions of NavigationController

Recently, I have done some iOS projects with Swift language, and I have some experiences. I have written down some profound problems to benefit myself and serve everyone

1. With NavigationController as the container, the font color of the status bar will not be controlled by the system. It can only take effect if it is set in the root ViewController in NavigationController. The code is as follows:


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

The choices are UIBarStyle. Black, UIBarStyle. Default, UIBarStyle. BlackOpaque, UIBarStyle. BlackTranslucent. The specific choices depend on the project requirements

2. Failure of sliding return effect after NavigationController is used as container

The problem is that navigationItem will be automatically generated as a navigation bar after push reaches the next page in storyboard. When we drag a button to the navigation bar and return to the position of the button,

And customize the return event, the sliding return effect will be invalid

The solution is as follows:

The root ViewController of NavigationController inherits UIGestureRecognizerDelegate, and viewDidLoad () is added

self.navigationController!.interactivePopGestureRecognizer!.delegate = self

The code for the replication method gestureRecognizerShouldBegin () is as follows:


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


Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: