I'm trying to follow this tutorial on building a custom transition. Once I got to a custom to the part that involves UIViewControllerAnimatedTransitioning, I began having errors. (I"m still new to swift, so it's taken a lot of effort with nothing to show so far).
I keep getting 2 errors. 1 -
Cannot assign value of type 'CircleTransitionAnimator' to type 'CAAnimationDelegate?'
2 -
Method does not override any method from its superclass
I'm guessing that the issue is related to UIViewControllerAnimatedTransitioning
class CircleTransitionAnimator: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.5
}
weak var transitionContext: UIViewControllerContextTransitioning?
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
self.transitionContext = transitionContext
var containerView = transitionContext.containerView()
var fromViewController = transitionContext.viewController(forKey: UITransitionContextFromViewControllerKey) as! ViewController
var toViewController = transitionContext.viewController(forKey: UITransitionContextToViewControllerKey) as! ViewController
var button = fromViewController.button
containerView.addSubview(toViewController.view)
var circleMaskPathInitial = UIBezierPath(ovalIn: (button?.frame)!)
var extremePoint = CGPoint(x: (button?.center.x)! - 0, y: (button?.center.y)! - toViewController.view.bounds.height)
var radius = sqrt((extremePoint.x*extremePoint.x) + (extremePoint.y*extremePoint.y))
var circleMaskPathFinal = UIBezierPath(ovalIn: (button?.frame)!.insetBy(dx: -radius, dy: -radius))
var maskLayer = CAShapeLayer()
maskLayer.path = circleMaskPathFinal.cgPath
toViewController.view.layer.mask = maskLayer
var maskLayerAnimation = CABasicAnimation(keyPath: "path")
maskLayerAnimation.fromValue = circleMaskPathInitial.cgPath
maskLayerAnimation.toValue = circleMaskPathFinal.cgPath
maskLayerAnimation.duration = self.transitionDuration(using: transitionContext)
maskLayerAnimation.delegate = self
maskLayer.add(maskLayerAnimation, forKey: "path")
}
override func animationDidStop(anim: CAAnimation!, finished flag: Bool) {
self.transitionContext?.completeTransition(!self.transitionContext!.transitionWasCancelled())
self.transitionContext?.viewController(forKey: UITransitionContextFromViewControllerKey)?.view.layer.mask = nil
}
}
iOS 10 moves animationDidStart
and animationDidStop
to a formal CAAnimationDelegate
protocol. Like beyowulf says, make the class conform to the delegate and remove the override
tag from the method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With