Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

having trouble using UIViewControllerAnimatedTransitioning with swift 3

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
}

}
like image 543
madgrand Avatar asked Jul 14 '16 01:07

madgrand


1 Answers

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.

like image 186
Jerry Avatar answered Sep 27 '22 16:09

Jerry