UIBezierPath CAAnimation 在 startAngle 改变时完成得太快

问题描述 投票:0回答:0

此代码将在 3 点钟位置绘制一个圆圈。持续时间设置为10秒,视觉上持续10秒。但是,我希望起始角度出现在 12 点钟位置,而不是 3 点钟位置。如果我将开始角度更改为 -(.pi / 2),代码会从 12 点钟的位置绘制圆,但视觉上会在大约 8 秒内完成,而不是指定的 10 秒?我已经看到将 animation.toValue 更改为较低数字的修复程序(请参阅评论中的评论),但为什么需要这样做?

let path = UIBezierPath(arcCenter: center, radius: 90, startAngle: 0, endAngle: .pi * 2, clockwise: true)
        
introAnimationLayer1 = CAShapeLayer()
introAnimationLayer1?.frame = animationView!.frame
introAnimationLayer1?.position = mainAnimationLayerPosition
introAnimationLayer1?.path = path.cgPath
introAnimationLayer1?.fillColor = UIColor.clear.cgColor
introAnimationLayer1?.lineCap = CAShapeLayerLineCap.square
introAnimationLayer1?.strokeColor = UIColor.red.cgColor
introAnimationLayer1?.lineWidth = 10
introAnimationLayer1?.fillColor = UIColor.clear.cgColor
introAnimationLayer1?.strokeStart = 0   
mainAnimationLayer.addSublayer(introAnimationLayer1!)
...
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.duration = 10
animation.timingFunction = CAMediaTimingFunction(name: .linear)
animation.fromValue = 0
animation.toValue = 1 // Changing this to 0.795 will make the animation complete in the expected duration
animation.fillMode = .forwards
animation.isRemovedOnCompletion = false
animation.delegate = self
introAnimationLayer1.add(animation, forKey: "startingAnimation1")
ios swift core-animation uibezierpath
© www.soinside.com 2019 - 2024. All rights reserved.