Completion block for popViewController

后端 未结 18 1591
离开以前
离开以前 2020-12-04 06:43

When dismissing a modal view controller using dismissViewController, there is the option to provide a completion block. Is there a similar equivalent for

18条回答
  •  醉梦人生
    2020-12-04 07:28

    I made a Swift version with extensions with @JorisKluivers answer.

    This will call a completion closure after the animation is done for both push and pop.

    extension UINavigationController {
        func popViewControllerWithHandler(completion: ()->()) {
            CATransaction.begin()
            CATransaction.setCompletionBlock(completion)
            self.popViewControllerAnimated(true)
            CATransaction.commit()
        }
        func pushViewController(viewController: UIViewController, completion: ()->()) {
            CATransaction.begin()
            CATransaction.setCompletionBlock(completion)
            self.pushViewController(viewController, animated: true)
            CATransaction.commit()
        }
    }
    

提交回复
热议问题