iOS navigation returned results

He said today that a newly discovered effect navigation returned

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool){
if viewController.isKind(of: ContainViewController.self){
viewController.navigationController?.setNavigationBarHidden(true, animated: animated)
}else{
viewController.navigationController?.setNavigationBarHidden(false, animated: animated)
}
}

Set setNavigationBarHidden this property willShow viewController will return a different effect oh ~

Use this time to add a ContainViewController navigationController pages and controllers can see this effect

   let nv = JTNavigationController.init(rootViewController: control)
    let ccv = LifeStoryboard.instantiateViewController(withIdentifier: "ContainViewController") as! ContainViewController
    ccv.view.addSubview(nv.view)
    ccv.addChildViewController(nv)
   ccv.hidesBottomBarWhenPushed = true

self.navigationController?.pushViewController(control, animated: true)


1695156-fb2f7a2a38c6e17b.PNG
IMG_3845.PNG

Under summary navigationController returned a total of three kinds of effects
1. with the use of a navigation bar that is too common a not explained

There is also a special effects


1695156-dbaecda0be097ec5.PNG
IMG_3847.PNG

Let's analyze this a good effect

Using JTNavigationController

First, the root controller is a navigation controller, the navigation controller manages all of the pages of push and pop operations, and navigation bar navigationBar the navigation controller is hidden, and is setNavigationBarHidden: a way to hide, rather than navgationBar. hidden = YES, because setNavigationBarHidden: in fact, the way directly to the navigationBar removed, and navgationBar.hidden = YES just let the navigationBar become transparent.
UINavigationControler the root followed by a UIViewController, because if we need to display interface itself is a UINavigationControler, it will be a problem, UINavigationControler nested UINavigationControler way is not permitted, and a third behind similar. so to be packed.

Then whenever push a ViewControler, was packed to the ViewController first bread out of a UINavigationController, then a UIViewController in UINavigationControler outsourcing, the reason for this is UINavigationControler can not push another UINavigationControler, so need to pack a layer of UIViewController.
Finally, we really are seeing on the screen is the navigation bar belong to this package UINavigationControler outside UIViewControler's because each page has its own navigation controller, and then there is the outermost layer of UINavigationControler to manage and push the page pop operation, we achieved what we wanted.

Guess you like

Origin blog.csdn.net/weixin_33885676/article/details/90925525