在AnimationController中使用核心动画时,iOS UINavigationController自定义交互控制器工作不正常
我在NavigationController中有用于转换的自定义动画控制器,我希望使其具有交互性,因此我创建了一个自定义交互控制器,它对其中一些控制器工作良好,但在使用CoreAnimations执行动画的控制器中,它不能正常工作 它自己启动和完成动画,因为在交互控制器在AnimationController中使用核心动画时,iOS UINavigationController自定义交互控制器工作不正常,ios,animation,uinavigationcontroller,core-animation,custom-transition,Ios,Animation,Uinavigationcontroller,Core Animation,Custom Transition,我在NavigationController中有用于转换的自定义动画控制器,我希望使其具有交互性,因此我创建了一个自定义交互控制器,它对其中一些控制器工作良好,但在使用CoreAnimations执行动画的控制器中,它不能正常工作 它自己启动和完成动画,因为在交互控制器finish()中没有调用,所以我留下了一个黑屏 以下是AnimationController中的代码: CATransaction.begin() let revealAnimation = CABasicAni
finish()
中没有调用,所以我留下了一个黑屏
以下是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()
@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
}
}
在我的发言中,代表:
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:
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()
@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
}
}
我做错了什么