Skip to content

Instantly share code, notes, and snippets.

@andrespch
Created April 19, 2017 14:57
Show Gist options
  • Save andrespch/8e97bdc273c6eb485366902595abdbc7 to your computer and use it in GitHub Desktop.
Save andrespch/8e97bdc273c6eb485366902595abdbc7 to your computer and use it in GitHub Desktop.
NavigationController Extension to push/pop with a completion closure
extension UINavigationController {
private func doAfterAnimatingTransition(animated: Bool, completion: @escaping (() -> Void)) {
if let coordinator = transitionCoordinator, animated {
coordinator.animate(alongsideTransition: nil, completion: { _ in
completion()
})
} else {
DispatchQueue.main.async {
completion()
}
}
}
public func pushViewController(viewController: UIViewController, animated: Bool, completion: @escaping (() -> Void)) {
pushViewController(viewController, animated: animated)
doAfterAnimatingTransition(animated: animated, completion: completion)
}
public func popViewController(animated: Bool, completion: @escaping (() -> Void)) {
popViewController(animated: animated)
doAfterAnimatingTransition(animated: animated, completion: completion)
}
public func popToRootViewController(animated: Bool, completion: @escaping (() -> Void)) {
popToRootViewController(animated: animated)
doAfterAnimatingTransition(animated: animated, completion: completion)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment