If you drag the edge of a UIViewController
to begin an interactive pop transition within a UINavigationController
, the UIViewController
un
I translated @Dima's answer to Swift for my project:
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
transitionCoordinator()?.notifyWhenInteractionEndsUsingBlock { context in
guard context.isCancelled(), let fromViewController = context.viewControllerForKey(UITransitionContextFromViewControllerKey) else { return }
self.navigationController(self, willShowViewController: fromViewController, animated: animated)
let animationCompletion: NSTimeInterval = context.transitionDuration() * Double(context.percentComplete())
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
self.navigationController(self, didShowViewController: fromViewController, animated: animated)
}
}
/* Your normal behavior goes here */
}
Note that I don't check for the existence of an implementation of navigationController(_:didShowViewController:animated:)
, although I believe this is checked at compile-time in Swift, and that you'll get a compiler error if you attempt to call this when it's unimplemented.