gpt4 book ai didi

ios - NSValue valueWithCATransform3D : in Swift3

转载 作者:搜寻专家 更新时间:2023-11-01 06:37:04 25 4
gpt4 key购买 nike

如何将下面的动画翻译成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获取可用 key 的完整列表。

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

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

关于ios - NSValue valueWithCATransform3D : in Swift3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40298678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com