自定义展开 segue 在 iOS11 中崩溃
Custom unwind segue crashing in iOS11
更新
玩这个我发现如果我从提供的控制器执行此操作,一切都会按预期工作:
self.dismiss(animated: true)
并执行自定义转场的动画。但是,如果我尝试使用这样的展开转场:
self.performSegue(withIdentifier: "logoDisplayed", sender: self)
然后我得到下面提到的崩溃。我还发现自定义转场仅在我将 'kind' 设置为 'Present modally' 时才有效。如果我将它设置为 'Custom' 然后我再次得到崩溃告诉我没有 perform()
即使显然有。
还在想办法解决这个问题。
原版Post
我知道这个之前已经谈过了(here, here and here)
但我无法在 iOS11 中使用自定义展开转场。下面是我正在使用的自定义转场。当我将它设置为模型 segue 的 class 时它工作得很好,但当我将它设置为 unwind segue 的 class 时它不起作用。相反,应用程序崩溃并出现此错误:
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()
}
}
有人知道我可能哪里出错了吗?
找到问题了。我在源控制器中有一些旧代码:
override func segueForUnwinding(to toViewController: UIViewController, from fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue? {
return AnimatedSegue(identifier: identifier, source: fromViewController, destination: toViewController)
}
正在调用并导致问题的。
更新
玩这个我发现如果我从提供的控制器执行此操作,一切都会按预期工作:
self.dismiss(animated: true)
并执行自定义转场的动画。但是,如果我尝试使用这样的展开转场:
self.performSegue(withIdentifier: "logoDisplayed", sender: self)
然后我得到下面提到的崩溃。我还发现自定义转场仅在我将 'kind' 设置为 'Present modally' 时才有效。如果我将它设置为 'Custom' 然后我再次得到崩溃告诉我没有 perform()
即使显然有。
还在想办法解决这个问题。
原版Post
我知道这个之前已经谈过了(here, here and here)
但我无法在 iOS11 中使用自定义展开转场。下面是我正在使用的自定义转场。当我将它设置为模型 segue 的 class 时它工作得很好,但当我将它设置为 unwind segue 的 class 时它不起作用。相反,应用程序崩溃并出现此错误:
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()
}
}
有人知道我可能哪里出错了吗?
找到问题了。我在源控制器中有一些旧代码:
override func segueForUnwinding(to toViewController: UIViewController, from fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue? {
return AnimatedSegue(identifier: identifier, source: fromViewController, destination: toViewController)
}
正在调用并导致问题的。