NavigationController のトランジションに使用するカスタム アニメーション コントローラーがあり、それをインタラクティブにしたいので、カスタム インタラクション コントローラーを作成しました。一部のコントローラーでは正常に動作しますが、CoreAnimations を使用してアニメーションを実行するコントローラーでは正常に動作します。正しく動作しません。
アニメーションを自動的に開始および終了します。Interaction Controllerfinish()
が呼び出されなかったため、黒い画面が残ります。
AnimationController のコードは次のとおりです。
CATransaction.begin()
let revealAnimation = CABasicAnimation(keyPath: "path")
revealAnimation.toValue = UIBezierPath(arcCenter: originPoint, radius: UIScreen.main.bounds.size.height*1.5, startAngle: 0, endAngle: 2*CGFloat.pi, clockwise: true).cgPath
revealAnimation.duration = transitionDuration
revealAnimation.isRemovedOnCompletion = false
revealAnimation.fillMode = kCAFillModeForwards
revealAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
circleMask.add(revealAnimation, forKey: nil)
let fadeAnimation2 = CABasicAnimation(keyPath: "opacity")
fadeAnimation2.toValue = 1.0
fadeAnimation2.duration = 0
fadeAnimation2.beginTime = CACurrentMediaTime() + transitionDuration/2
fadeAnimation2.isRemovedOnCompletion = false
fadeAnimation2.fillMode = kCAFillModeForwards
fadeAnimation2.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
toViewController.view.layer.add(fadeAnimation2, forKey: nil)
let fadeAnimation = CABasicAnimation(keyPath: "fillColor")
fadeAnimation.toValue = UIColor.clear.cgColor
fadeAnimation.duration = transitionDuration/4
fadeAnimation.beginTime = CACurrentMediaTime() + 3*transitionDuration/4
fadeAnimation.isRemovedOnCompletion = false
fadeAnimation.fillMode = kCAFillModeForwards
fadeAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
fadeAnimation.delegate = self
circleMask.add(fadeAnimation, forKey: nil)
CATransaction.commit()
私の CAAnimationDelegate では:
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
if flag {
circleMask.removeAllAnimations()
circleMask.removeFromSuperlayer()
toViewController.view.layer.opacity = 1
toViewController.view.layer.removeAllAnimations()
if transitionContext.transitionWasCancelled {
toViewController.view.removeFromSuperview()
} else {
fromViewController.view.removeFromSuperview()
}
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
}
最後に、InteractionController は次のとおりです。
@objc func handleGesture(_ gestureRecognizer: UIPanGestureRecognizer) {
let translation = gestureRecognizer.translation(in: gestureRecognizer.view!.superview!)
var progress = (translation.x / 200)
progress = CGFloat(fminf(fmaxf(Float(progress), 0.0), 1.0))
switch gestureRecognizer.state {
case .began:
interactionInProgress = true
viewController?.navigationController?.popViewController(animated: true)
case .changed:
shouldCompleteTransition = progress > 0.5
update(progress)
case .cancelled:
interactionInProgress = false
cancel()
case .ended:
interactionInProgress = false
if shouldCompleteTransition {
finish()
} else {
cancel()
}
default:
break
}
}
私は何を間違っていますか?