自定义UIViewController过渡动画适用于演示,但不适用于解雇

时间:2018-04-18 20:34:19

标签: ios swift uikit

我有UINavigationController A,这是UISplitViewController的“左侧”视图控制器,我在UINavigationController B上以模式方式呈现UINavigationController A。此模式演示使用storyboard segue执行,并在Interface Builder中设置以下属性:Kind = Present ModallyPresentation = Over Current ContextTransition = {{ 1}},Default = Animates

true的根视图控制器中,我有以下属性:

UINavigationController A

以下是prepareForSegue方法的实现:

let themesTransitionDelegate = ThemesTransitionDelegate()

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { segue.destination.transitioningDelegate = themesTransitionDelegate segue.destination.view.frame = view.bounds } 的实施如下:

ThemesTransitionDelegate

我的自定义动画在呈现模态时工作正常,但从未调用class ThemesTransitionDelegate: NSObject, UIViewControllerTransitioningDelegate { func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { return ThemesTransitionAnimator() } func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { // THIS IS NEVER CALLED! return ThemesTransitionAnimatorDismiss() } } 并且未使用我的自定义解雇动画 - 而是使用标准模态解雇动画。

我正在使用从animationController(forDismissed dismissed: UIViewController)的根视图控制器调用的dismiss(animated: true, completion: nil)来触发解除所呈现的模态。我已确认,当解雇被触发时,UINavigationController B的{​​{1}}不是零。

这里可能出现什么问题?

1 个答案:

答案 0 :(得分:2)

您在故事板中设置了错误的modalPresentationStyle。使用UIModalPresentationCustom

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {        
    segue.destination.modalPresentationStyle = .custom //Custom presentation
    segue.destination.transitioningDelegate = themesTransitionDelegate
    segue.destination.view.frame = view.bounds
}