Completion block for popViewController

后端 未结 18 1636
离开以前
离开以前 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:20

    For iOS9 SWIFT version - works like a charm (hadn't tested for earlier versions). Based on this answer

    extension UINavigationController {    
        func pushViewController(viewController: UIViewController, animated: Bool, completion: () -> ()) {
            pushViewController(viewController, animated: animated)
    
            if let coordinator = transitionCoordinator() where animated {
                coordinator.animateAlongsideTransition(nil) { _ in
                    completion()
                }
            } else {
                completion()
            }
        }
    
        func popViewController(animated: Bool, completion: () -> ()) {
            popViewControllerAnimated(animated)
    
            if let coordinator = transitionCoordinator() where animated {
                coordinator.animateAlongsideTransition(nil) { _ in
                    completion()
                }
            } else {
                completion()
            }
        }
    }
    

提交回复
热议问题