UIModalPresentationOverCurrentContext is intended to be used to present the content over your current viewController. What that means is, if you have animation or view changes inside your parentViewController, you can still see through the childViewController if the view is transparent. So, it also means that view never disappears for view over current context. It seems legit that viewWillAppear:, viewDidAppear:, viewWillDisappear: and viewDidDisappear do not get called.
You can however use UIModalPresentationStyle.Custom to have exact same behavior to present over current context. You wont receive view appearance callbacks but you can create your own custom UIPresentationController to get those callbacks.
Here is an example implementation,
class MyFirstViewController: UIViewController {
....
func presentNextViewController() {
let myNextViewController = MyNextViewController()
myNextViewController.modalPresentationStyle = UIModalPresentationStyle.Custom
myNextViewController.transitioningDelegate = self
presentViewController(myNextViewController, animated: true) { _ in
}
}
...
}
extension MyFirstViewController: UIViewControllerTransitioningDelegate {
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController?
{
let customPresentationController = MyCustomPresentationController(presentedViewController: presented, presentingViewController: presenting)
customPresentationController.appearanceDelegate = self
return customPresentationController
}
}
extension MyFirstViewController: MyCustomApprearanceDelegate {
func customPresentationTransitionWillBegin() {
print("presentationWillBegin")
}
func customPresentationTransitionDidEnd() {
print("presentationDidEnd")
}
func customPresentationDismissalWillBegin() {
print("dismissalWillBegin")
}
func customPresentationDismissalDidEnd() {
print("dismissalDidEnd")
}
}
protocol MyCustomApprearanceDelegate: class {
func customPresentationTransitionWillBegin()
func customPresentationTransitionDidEnd()
func customPresentationDismissalWillBegin()
func customPresentationDismissalDidEnd()
}
class MyCustomPresentationController: UIPresentationController {
weak var appearanceDelegate: MyCustomApprearanceDelegate!
override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
}
override func presentationTransitionWillBegin() {
appearanceDelegate.customPresentationTransitionWillBegin()
}
override func presentationTransitionDidEnd(completed: Bool) {
appearanceDelegate.customPresentationTransitionDidEnd()
}
override func dismissalTransitionWillBegin() {
appearanceDelegate.customPresentationDismissalWillBegin()
}
override func dismissalTransitionDidEnd(completed: Bool) {
appearanceDelegate.customPresentationDismissalDidEnd()
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…