gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 07:03:07 27 4
gpt4 key购买 nike

我有UINavigationController A , 这是 UISplitViewController 的“左侧” View Controller 我正在展示 UINavigationController B模态上 UINavigationController A .此模态演示是通过在 Interface Builder 中设置以下属性的 Storyboard segue 执行的:Kind = Present Modally , Presentation = Over Current Context , Transition = Default , Animates = true

UINavigationController A 的 Root View Controller 中,我有以下属性:

let themesTransitionDelegate = ThemesTransitionDelegate()

以及 prepareForSegue 方法的以下实现:

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 调用的 Root View Controller 触发呈现模态的解除。我已经确认 UINavigationController BtransitioningDelegate触发解雇时不为零。

这里可能出了什么问题?

最佳答案

您在 Storyboard中设置了错误的 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
}

关于ios - 自定义 UIViewController 过渡动画适用于演示,但不适用于解雇,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49908596/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com