我有UINavigationController A
,这是UISplitViewController
的“左侧”视图控制器,我在UINavigationController B
上以模式方式呈现UINavigationController A
。此模式演示使用storyboard segue执行,并在Interface Builder中设置以下属性:Kind
= Present Modally
,Presentation
= Over Current Context
,Transition
= {{ 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}}不是零。
这里可能出现什么问题?
答案 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
}