首页 > 解决方案 > ToView 在 Swift 中出现在 FromView 后面

问题描述

我通过向下一个视图控制器呈现自定义过渡动画来做一个相当简单的转场。

本质上,transition 会在屏幕外创建 toView,然后将其从右侧滑过 fromView,而 fromView 会以稍慢的速度从左侧滑出。解雇过渡则相反。

我的问题是在解除 toView 以返回 fromView 后,当我再次触发 segue 时,toView 在 fromView 下滑动而不是在上面滑动。这不会在第一次过渡时发生,但在之后的每个人身上都会发生。

我一生都无法弄清楚它为什么会这样做,更不用说如何解决它了。任何帮助都是极好的。

转义代码:

let storyboard = UIStoryboard(name: kOnboardingSignupStoryboard, bundle: nil) let vc = storyboard.instantiateViewController(withIdentifier: kOnboardingErrorIdentifier) as! OnboardingErrorViewController vc.transitioningDelegate = self vc.errorMessage = kErrorIncorrectPin self.present(vc, animated: true, completion: nil)

关闭代码:

dismiss(animated: true, completion: nil)

过渡扩展:

extension OnboardingErrorViewController: UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    return FromRightDeck()
}

func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    return DismissFromRightDeck()
}

问题的 GIF

标签: iosswiftxcodeview

解决方案


好的,所以我在深入研究动画代码后设法解决了它。最初我不认为这与它有任何关系,因为它在第一次和每隔一次我使用动画时都可以正常工作。但是,有一行错误的代码推送到我在测试中使用的 toView z 位置,这导致了这个问题。


推荐阅读