我想实现一个自定义的塞格,它将从右向左带动视图控制器。问题是我的应用程序崩溃时,我按下按钮,以执行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)
}
)
}
}
以我的故事板我有一个UIButtoon我使用自定义赛格瑞并列(由我CustomTransition类生成的一个)。当我运行该应用程序并点击按钮时,我的应用程序崩溃与上面发布的错误。我不明白为什么它会崩溃。我发现网上的每篇文章都与我实施它的方式类似。
什么是navigationController?你的sourceVC必须是UINavigationController吗?如果源和目标只是两个普通的UIViewControllers,就像原始问题一样? – Cindeselia
@Cindeselia你可以从属性'sourceVC.navigationController'访问导航控制器。 – Astoria