No Swipe Back when hiding Navigation Bar in UINavigationController

前端 未结 18 714
生来不讨喜
生来不讨喜 2020-12-04 06:34

I love the swipe pack thats inherited from embedding your views in a UINavigationController. Unfortunately i cannot seem to find a way to hide the Naviga

18条回答
  •  一个人的身影
    2020-12-04 07:03

    The answer of Hunter Monk is really awesome, but unfortunately in iOS 13.3.1, it does not work.

    I will explain another way to hide UINavigationBar and not lose swipe to back gesture. I have tested on iOS 13.3.1 and 12.4.3 and it works.

    You need to create a custom class of UINavigationController and set that class for UINavigationController in Storyboard

    Do NOT hide the NavigationBar on the Storyboard

    Example on Storyboard:

    And finally, put this: navigationBar.isHidden = true in viewDidLoad of CustomNavigationController class.

    Make sure, do NOT use this method setNavigationBarHidden(true, animated: true) for hiding the NavigationBar.

    import UIKit
    
    class CustomNavigationController: UINavigationController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            navigationBar.isHidden = true
        }
    }
    

提交回复
热议问题