我正在尝试遵循this关于构建自定义过渡的教程。一旦我对涉及UIViewControllerAnimatedTransitioning的部分进行了自定义,就开始出现错误。 (我还是不快的新手,所以到目前为止已经花了很多功夫而没有任何显示)。

我不断收到2个错误。 1-



2-



我猜这个问题与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将animationDidStartanimationDidStop移至正式的CAAnimationDelegate协议(protocol)。就像beyowulf所说的那样,使类符合委托(delegate),并从方法中删除override标记。

关于swift - 在Swift 3中使用UIViewControllerAnimatedTransitioning遇到麻烦,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38364086/

10-12 14:35