我目前有一個用作視頻進度指示器的動畫,效果很好。不過,現在我們有一項功能,允許用戶通過點擊它跳過視頻前2.5秒,因此我正在嘗試實施進度指示器動畫以向動畫中跳過2.5秒。我如何將動畫向前跳過2.5秒?我試過「animationGroup.timeOffset = 2.5」,但它不起作用。在CABasicAnimation(iOS)中跳過
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)
}
是的,這就是我不得不做的(見我的答案) –