我從那個狀態,我CAAnimationGroup
兩個旋轉的動畫,一個從零開始,另一種是重複和autoreverses:CAAnimationGroup的最大持續時間值(CFTimeInterval)是多少?
- (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"];
}
由於CFTimeInterval被定義爲double,我嘗試設置動畫組的持續時間到,但會阻止動畫組運行。但是,如果我將它設置爲一個很大的數字,例如10000,它運行良好。在CAAnimationGroup
的持續時間內,我可以使用的最大數字是多少,以確保其儘可能接近無窮?
UPDATE:看來,如果我把一個非常大的值,例如DBL_MAX/4.0
則凍結了一秒鐘,然後開始動畫。如果我輸入值DBL_MAX/20.0
,那麼開始時的凍結就會小很多。看起來持續這麼大的價值會導致它凍結。除了在持續時間內使用非常大的值以外,還有更好的方法嗎?
你正在努力使這組動畫的重複下去嗎? – 2013-03-27 17:19:50
是的,但我只希望小組的第二部分能夠永遠重複。 – jowie 2013-03-27 17:22:39
你確定需要設置持續時間嗎?如果讓它未設置會發生什麼? – 2013-03-27 17:25:11