左右摇摆
let transform : CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
transform.fromValue = NSNumber(float: -Float(M_PI_4)/2)
transform.toValue = NSNumber(float: Float(M_PI_4)/2)
//是否累积
transform.cumulative = false
//自动反向
transform.autoreverses = true
transform.removedOnCompletion = true
transform.repeatCount = Float(MAXFLOAT)//100
transform.duration = 1
transform.fillMode = kCAFillModeBoth
let group : CAAnimationGroup = CAAnimationGroup()
group.animations = [transform]
group.duration = CFTimeInterval(MAXFLOAT) * 5
group.repeatCount = Float(MAXFLOAT)
view.layer.addAnimation(group, forKey:"transform")
注意事项
cumulative:
If true then the current value of the animation is the value at the end of the previous repeat cycle, plus the value of the current repeat cycle. If false, the value is simply the value calculated for the current repeat cycle. Defaults to NO.
即如果为真,那么动画下一次的起点就是上一次的终点,进行旋转角度运动。如果为假,动画和下一次一致