【发布时间】:2017-11-23 20:42:44
【问题描述】:
更新
玩弄这个我发现如果我从提供的控制器中执行此操作,一切都会按预期工作:
self.dismiss(animated: true)
然后自定义 segue 的动画被执行。但是,如果我尝试使用这样的 unwind segue:
self.performSegue(withIdentifier: "logoDisplayed", sender: self)
然后我得到下面提到的崩溃。此外,我发现自定义 segue 仅在我将“种类”设置为“模态呈现”时才有效。如果我将其设置为“自定义”,那么我会再次收到崩溃消息,告诉我没有 perform(),即使显然有。
仍在尝试解决这个问题。
原帖
我知道之前已经讨论过这个问题(here、here 和 here)
但我无法在 iOS11 中使用自定义展开转场。下面是我正在使用的自定义 segue。当我将它设置为模型转场的类时它可以完美运行,但是当我将它设置为展开转场的类时它不起作用。相反,应用程序因以下错误而崩溃:
2017-11-20 22:29:09.640934+1100 Crux[46709:6046351] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Could not perform segue with identifier 'logoDisplayed'.
A segue must either have a performHandler or it must override -perform.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001100c012b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010f06bf41 objc_exception_throw + 48
2 UIKit 0x0000000111c1061d -[UIStoryboardSegue _prepare] + 0
3 Crux 0x000000010dacecc8 _T04Crux13AnimatedSegueC7performyyF + 280
...
segue 的设置如下:
我的 segue 的代码是这样的:
class FadeInAnimator: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 2.0
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
let toVC = transitionContext.viewController(forKey:UITransitionContextViewControllerKey.to)
containerView.addSubview(toVC!.view)
toVC!.view.alpha = 0.0
let duration = transitionDuration(using:transitionContext)
UIView.animate(withDuration:duration,
animations: {
toVC!.view.alpha = 1.0
},
completion: { finished in
let cancelled = transitionContext.transitionWasCancelled
transitionContext.completeTransition(!cancelled)
})
}
}
class AnimatedSegue:UIStoryboardSegue, UIViewControllerTransitioningDelegate {
override func perform() {
source.transitioningDelegate = self
destination.transitioningDelegate = self
super.perform()
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return FadeInAnimator()
}
func animationController(forPresented presented: UIViewController,
presenting: UIViewController,
source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return FadeInAnimator()
}
}
有人知道我哪里出错了吗?
【问题讨论】:
-
Xcode 9.1,iOS 11 模拟器。我无法重现此崩溃。也许尝试在一个全新的项目中重新创建?
标签: ios uistoryboardsegue