如何在动画期间动态访问半径? (在 CGAffineTransform 期间可能)

How to access radius dynamically during animation? (possible during CGAffineTransform)

我正在使用两个简单的 CGAffineTransform 来向上和向下缩放圆形 UIView,但我希望能够在动画发生时动态访问 touchesBegan() 中的半径并检查它是否等于在这一点上的某个值。

困难在于我需要在动画仍在发生时检查半径。我并没有完全接受 CGAffineTransforms 方法,所以我非常乐意以另一种方式为圆制作动画,如果这意味着能够访问半径的话。谢谢!

我不知道该怎么做。下面是我的代码(欢迎提示!):

func grow() {

    UIView.animateWithDuration(2.3, delay: 0.0,
        options: UIViewAnimationOptions.CurveEaseIn,
        animations: {
            self.circle2.transform = CGAffineTransformMakeScale(1.5, 1.5)
        },
        completion: ({ finished in
            if (finished) {
                self.shrink()
            }
        }))
}

func shrink() {

    UIView.animateWithDuration(2.3, delay: 0.0,
        options: UIViewAnimationOptions.CurveEaseInOut,
        animations: {
            self.circle2.transform = CGAffineTransformMakeScale(0.5, 0.5)
        },
        completion: ({ finished in
            if (finished) {
                self.grow()
            }
        }))
}

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
        /*
        if radius == certain value
            {
                //do something
            }
        */
    }

首先,我建议使用普通的 CABasicAnimation 或 CAKeyframeAnimation 制作此动画,因为您可以使用 anim.repeatCount = .infinity 而不是来回调用的完成处理程序。

动画的当前状态可以通过circle2.layer.presentationLayer访问。如前所述 in this question,您可以使用它的 frame 将转换考虑在内。