ViewController should call
self!.beginAppearanceTransition(false, animated:true)
self!.endAppearanceTransition()
at appropriate location.
otherwise, the ViewController's viewWillDisappear, viewDidDisappear, viewWillAppear, viewDidAppear, will not be called when ModalViewController being presented or dismissed.
self.animator.presentationBeforeHandler = { [weak self] (containerView: UIView, transitionContext:
UIViewControllerContextTransitioning) in
self!.beginAppearanceTransition(false, animated:true) //added
...
self!.animator.presentationCompletionHandler = {(containerView: UIView, completeTransition: Bool) in
if completeTransition {
self!.view.removeFromSuperview()
self!.modalVC.view.removeFromSuperview()
containerView.addSubview(self!.modalVC.view)
self!.animator.interactiveType = .Dismiss
self!.animator.gestureTargetView = self!.playerVC.backgroundView
self!.animator.direction = .Bottom
self!.endAppearanceTransition() //added
} else {
UIApplication.sharedApplication().keyWindow!.addSubview(self!.view)
self!.beginAppearanceTransition(true, animated: false) //added
self!.endAppearanceTransition() //added
}
}
}
self!.beginAppearanceTransition(true, animated:true) //added
self!.animator.dismissalCancelAnimationHandler = { (containerView: UIView) in
...
self!.animator.dismissalCompletionHandler = { (containerView: UIView, completeTransition: Bool) in
if completeTransition {
self!.modalVC.view.removeFromSuperview()
self!.animator.gestureTargetView = self!.tabBarPalettle
self!.animator.interactiveType = .Present
UIApplication.sharedApplication().keyWindow!.addSubview(self!.view)
self!.endAppearanceTransition() // added
} else {
self!.beginAppearanceTransition(false, animated: false) //added
self!.endAppearanceTransition() //added
}
}