gpt4 book ai didi

ios - 动画从左到右继续

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:03:35 25 4
gpt4 key购买 nike

我正在尝试实现一个自定义 segue,它将使 viewcontroller 从右到左带有动画。问题是当我按下按钮以执行到所需 Controller 的 segue 时,我的应用程序崩溃了。我收到以下错误:

Could not create a segue of class '(null)'

我是如何实现的?我创建了一个新类并使用以下代码覆盖了执行函数:

import UIKit

class CustomTransition: UIStoryboardSegue {

override func perform()
{
let src = self.source
let dst = self.destination

src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
dst.view.transform = CGAffineTransform(translationX: -src.view.frame.size.width, y: 0)

UIView.animate(withDuration: 0.25,
delay: 0.0,
options: UIViewAnimationOptions.curveEaseInOut,
animations: {
dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
},
completion: { finished in
src.present(dst, animated: false, completion: nil)
}
)
}

在我的 Storyboard 中,我有一个 UIButtoon,我使用自定义 segue(由我的 CustomTransition 类生成的)绑定(bind)它。当我运行应用程序并点击按钮时,我的应用程序崩溃并出现上面发布的错误。我不明白为什么它会崩溃。我在网络上找到的每篇文章都与我实现它的方式相似。

最佳答案

为此,您是否尝试过不使用 segues 而使用 transitions?

// create transition
let transition = CATransition()
transition.duration = 0.3
// check other types
transition.type = kCATransitionMoveIn
// move from left
transition.subtype = kCATransitionFromLeft
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
navigationController.view.layer.addAnimation(transition, forKey: kCATransition)
// push controller
navigationController.pushViewController(controller, animated: false)

关于ios - 动画从左到右继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39789873/

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