我刚刚花了最后几个小时来查找一个偶然发现的错误,该错误恰好位于过渡驱动程序对象中,其中interruptibleAnimator
方法多次调用,其中:
UIViewPropertyAnimator
完成闭包包含对[unowned self]
的引用,以完成其过渡控制器通过self.context.completeTransition(true)
传递的过渡上下文UIViewControllerAnimatedTransitioning
并且是UINavigationControllerDelegate
,通过其animate
方法传递了上下文extension NavigationTransitionController: UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return transitionDuration
}
func animationEnded(_ transitionCompleted: Bool) {
// Clean up our helper object and any additional state
transitionDriver = nil
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
transitionDriver = TransitionDriver(context: transitionContext, duration: transitionDuration)
interruptibleAnimator(using: transitionContext).startAnimation()
}
func interruptibleAnimator(using transitionContext: UIViewControllerContextTransitioning) -> UIViewImplicitlyAnimating {
return transitionDriver!.transitionAnimator
}
除非我在这里缺少一些非常基本的知识,否则我不知道为什么过渡控制器将对
interruptibleAnimator
方法进行多次调用。我的结构受到Apple演示here in their WWDC 2016 talk的启发;如果您下载了该文件,则放置一个断点并启动其Photo Transitioning应用程序,您会发现自己在这种情况下针对同一过渡两次调用了此方法。
有人能启发我是否追赶幽灵,或者这是否是合法的怪异行为?
最佳答案
苹果在UIViewControllerAnimatedTransitioning
的“标题文档”中声明:
/// A conforming object implements this method if the transition it creates can
/// be interrupted. For example, it could return an instance of a
/// UIViewPropertyAnimator. It is expected that this method will return the same
/// instance for the life of a transition.
@available(iOS 10.0, *)
optional public func interruptibleAnimator(using transitionContext: UIViewControllerContextTransitioning) -> UIViewImplicitlyAnimating
第29:34分钟在WWDC Session 2016中声明了相同的内容。幻灯片27:33的示例实现似乎具有误导性/错误性。
多次调用它的原因超出了我的了解。
关于ios - UIViewControllerAnimatedTransitioning:多次调用interruptibleAnimator?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44834400/