I have two rotation animations in my CAAnimationGroup , which starts from zero, and the other, repeating and autoversion from this state:
- (void)addWobbleAnimationToView:(UIView *)view amount:(float)amount speed:(float)speed { NSMutableArray *anims = [NSMutableArray array]; // initial wobble CABasicAnimation *startWobble = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; startWobble.toValue = [NSNumber numberWithFloat:-amount]; startWobble.duration = speed/2.0; startWobble.beginTime = 0; startWobble.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [anims addObject:startWobble]; // rest of wobble CABasicAnimation *wobbleAnim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; wobbleAnim.fromValue = [NSNumber numberWithFloat:-amount]; wobbleAnim.toValue = [NSNumber numberWithFloat:amount]; wobbleAnim.duration = speed; wobbleAnim.beginTime = speed/2.0; wobbleAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; wobbleAnim.autoreverses = YES; wobbleAnim.repeatCount = INFINITY; [anims addObject:wobbleAnim]; CAAnimationGroup *wobbleGroup = [CAAnimationGroup animation]; wobbleGroup.duration = DBL_MAX; // this stops it from working wobbleGroup.animations = anims; [view.layer addAnimation:wobbleGroup forKey:@"wobble"]; }
Since CFTimeInterval is defined as double, I'm trying to set the animation group duration to DBL_MAX , but this stops the animation group from starting. However, if I install it on a large number, for example 10000, it works fine. What is the maximum number I can use during a CAAnimationGroup to ensure that it works as close to infinity as possible?
UPDATE: It seems that if I put a very large value, for example DBL_MAX / 4.0 , then it freezes for a second and then starts the animation. If I set the value DBL_MAX / 20.0 , then the freeze at the beginning is much less. It seems that so much importance for duration causes it to freeze. Is there a better way to do this otherwise than using a very large value for duration?
jowie source share