UINavigationController Interactive Pop Gesture Not Working?

前端 未结 10 1438
你的背包
你的背包 2020-12-13 10:02

So I have a navigation controller in my built for iOS 7 app. The titleView is visible, as well as the back button and navigation bar its self. For some reason, the interac

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 10:35

    Generically add interactive pop gesture to the whole app.

    XCODE: 9.0, Swift: 4.0

    Preferably create UINavigationController in AppDelegate.swift

    1. Create a navigation controller
    // I created a global variable, however not necessarily you will be doing this way
    var nvc: UINavigationController!
    
    1. implement UIGestureRecognizerDelegate
    class AppDelegate: UIResponder, UIApplicationDelegate, UIGestureRecognizerDelegate {
    
    1. Instantiat UINavigationController in application didFinishLaunchingWithOptions function
    nvc=UINavigationController()
    
    // For interactive pop gesture
    nvc.navigationBar.isHidden=true
    nvc?.interactivePopGestureRecognizer?.delegate=self
    
    1. Extra step, add controller to navigation controller in application didFinishLaunchingWithOptions function
    window=UIWindow()
    window?.rootViewController=nvc
    window?.makeKeyAndVisible()
    
    // BaseViewController is sample controller i created with xib
    nvc.pushViewController(BaseViewController(), animated: true)
    
    1. Implement gusture recognizer, add below code to AppDelegate.swift
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
            return true
        }
    



    Note: See other post in this section for the difference between

    self.navigationController?.navigationBar.isHidden=true
    

    And

    self.navigationController?.isNavigationBarHidden = true
    

提交回复
热议问题