NSValue valueWithCATransform3D:在 Swift3 中

NSValue valueWithCATransform3D: in Swift3

如何将下面的动画翻译成Swift3?

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
scaleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(2.5, 2.5, 1)];

我目前拥有的是

let circleEnlargeAnimation = CABasicAnimation(keyPath: "transform.scale")
circleEnlargeAnimation.fromValue = CATransform3DIdentity
circleEnlargeAnimation.toValue = CATransform3DMakeScale(10.0, 10.0, 1.0)

但是我的动画不工作...下面是完整的动画代码:

    let shapeLayer = CAShapeLayer()
    let center = CGPoint(x: sampleButton.bounds.width/2.0, y: sampleButton.bounds.height/2.0)
    let radius = CGFloat(10.0)

    let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: 0.0, endAngle: (CGFloat(360.0 * M_PI) / 180.0), clockwise: true)
    shapeLayer.path = path.cgPath
    shapeLayer.fillColor = UIColor.white.cgColor
    shapeLayer.strokeColor = UIColor.white.cgColor
    shapeLayer.lineCap = kCALineCapRound

    shapeLayer.frame = sampleButton.bounds
    let circleEnlargeAnimation = CABasicAnimation(keyPath: "transform.scale")
    circleEnlargeAnimation.fromValue = CATransform3DIdentity
    circleEnlargeAnimation.toValue = CATransform3DMakeScale(10.0, 10.0, 1.0)
    circleEnlargeAnimation.duration = 1.0
    shapeLayer.add(circleEnlargeAnimation, forKey: nil)

    sampleButton.layer.addSublayer(shapeLayer)

它只显示一个圆圈但没有动画...

您应该使用带有标量数值的键 transform.scale 或带有矩阵值的 transform。有关可用密钥的完整列表,请参阅 Key Value Coding Extensions in Core Animation Programming Guide

您可以创建一个矩阵值,例如:

NSValue(caTransform3D:CATransform3DMakeScale(10.0, 10.0, 1.0))