我目前有一个动画,可用作视频的进度指示器,效果很好。但是,现在我们有了一项功能,允许用户通过点击它将视频向前跳过2.5秒,因此,我正在尝试实现进度指示器动画,从而将其向前跳过2.5秒。如何跳过动画2.5秒钟?我已经尝试过“ animationGroup.timeOffset = 2.5”,但是它不起作用。
func performProgressIndicatorAnimation(duration: Float64) {
layer.mask = nil
layer.speed = 1.0
self.duration = duration
let strokeStartAnimation = CABasicAnimation(keyPath: "strokeStart")
strokeStartAnimation.fromValue = 0
strokeStartAnimation.toValue = 1
strokeStartAnimation.duration = duration
strokeStartAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animationGroup = CAAnimationGroup()
animationGroup.duration = duration
animationGroup.animations = [strokeStartAnimation]
externalCircle.addAnimation(animationGroup, forKey: "animationGroup")
}
//在这里绘制我的externalCircle:
private func drawCircles() {
let externalCirclePath = UIBezierPath(roundedRect: CGRectMake(0, 0, bounds.height, bounds.height), cornerRadius: bounds.height / 2)
externalCircle.path = externalCirclePath.CGPath
externalCircle.fillColor = UIColor.clearColor().CGColor
externalCircle.strokeColor = UIColor.whiteColor().CGColor
externalCircle.lineWidth = 2
let internalCircleRadius = bounds.size.height / 5
let internalCirclePath = UIBezierPath(roundedRect: CGRectMake(0, 0, internalCircleRadius * 2, internalCircleRadius * 2), cornerRadius: internalCircleRadius)
internalCircle.path = internalCirclePath.CGPath
internalCircle.fillColor = UIColor.whiteColor().CGColor
internalCircle.position = CGPointMake(CGRectGetMidX(bounds) - internalCircleRadius,
CGRectGetMidY(bounds) - internalCircleRadius);
layer.addSublayer(internalCircle)
layer.addSublayer(externalCircle)
}
最佳答案
如果您使用timeOffset跳过一定比例的动画,则动画仍将播放相同的总持续时间。动画只是循环播放并再次播放,直到它最初开始为止。
例如:动画:A-> B-> C。如果使用timeOffSet以便从B开始,它将是:B-> C-> A
在这种情况下,我认为您可以关闭此动画,然后添加新的动画。