Completion handler for UINavigationController “pushViewController:animated”?

前端 未结 9 1092
礼貌的吻别
礼貌的吻别 2020-11-30 18:08

I\'m about creating an app using a UINavigationController to present the next view controllers. With iOS5 there´s a new method to presenting UIViewControl

9条回答
  •  醉话见心
    2020-11-30 18:11

    Here is the Swift 4 version with the Pop.

    extension UINavigationController {
        public func pushViewController(viewController: UIViewController,
                                       animated: Bool,
                                       completion: (() -> Void)?) {
            CATransaction.begin()
            CATransaction.setCompletionBlock(completion)
            pushViewController(viewController, animated: animated)
            CATransaction.commit()
        }
    
        public func popViewController(animated: Bool,
                                      completion: (() -> Void)?) {
            CATransaction.begin()
            CATransaction.setCompletionBlock(completion)
            popViewController(animated: animated)
            CATransaction.commit()
        }
    }
    

    Just in case someone else needs this.

提交回复
热议问题