2016-07-14 19 views
9

Ich versuche this Tutorial zum Erstellen eines benutzerdefinierten Übergangs zu folgen. Sobald ich zu einem benutzerdefinierten Teil von UIViewControllerAnimatedTransitioning kam, begann ich Fehler zu haben. . (I "m noch neu zu schnell, so dass er sich sehr viel Mühe mit bisher nichts zeigen genommen wird)Probleme bei der Verwendung von UIViewControllerAnimatedTransitioning mit swift 3

Ich erhalte 2 Fehler. 1 -

Wert kann nicht vom Typ zuweisen‚CircleTransitionAnimator‘ um 'CAAnimationDelegate?'

2 -

Methode außer Kraft setzen keine Methode aus seiner übergeordneten Klasse

Ich vermute, dass das Problem auf UIViewControllerAnimatedTransitioning zusammenhängt

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 
} 

} 
+4

Versuchen Sie, 'CAAnimationDelegate' wie' Klasse CircleTransitionAnimator: NSObject, UIViewControllerAnimatedTransitioning, CAAnimationDelegate' hinzuzufügen. Entfernen Sie 'override' von' override func animationDidStop (anim: CAAnimation !, Fertigmarkierung: Bool) ' – beyowulf

Antwort

17

iOS 10 bewegt animationDidStart und animationDidStop zu einem formalen CAAnimationDelegate Protokoll. Wie beyowulf sagt, machen Sie die Klasse mit dem Delegierten konform und entfernen Sie das override-Tag aus der Methode.

+0

Ich habe das gerade gemacht, und der Fehler ist verschwunden. Ich kenne den Low-Level-Grund nicht, wie sich das in iOS 10 ändert. In Int 9 muss die Klasse nicht "CAAnimationDelegate" anpassen und es sollte "override" sein. –