func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 10
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
let toView = transitionContext.view(forKey: .to)!
let menuView = presenting ? toView : transitionContext.view(forKey: .from)!
containerView.addSubview(toView)
containerView.bringSubviewToFront(menuView)
CATransaction.begin()
CATransaction.setCompletionBlock {
menuView.layer.backgroundColor = UIColor.red.cgColor
transitionContext.completeTransition(true)
}
CATransaction.setAnimationDuration(self.transitionDuration(using: transitionContext))
menuView.layer.backgroundColor = UIColor.red.cgColor
CATransaction.commit()
}
我想在导航控制器的过渡动画中使用隐式动画。我想将背景颜色从原来的更改为red
. 但是,menuView
的颜色会立即更改,并且也会立即调用完成块,而不是在 10 秒后。
知道这里有什么问题吗?