开发者

Animation repeat

I have to commit the same animation again for some reason.

- (void)startAnimation {
    NSLog(@"startAnimation called:shouldContinue = %u",shouldContinue);
    shouldContinue = YES;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:开发者_StackOverflow社区3];
    [UIView setAnimationRepeatCount:10];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop: finished: context:)];
    // bulabula...
    [UIView commitAnimations];
}

- (void)cancelAnimation {
    shouldContinue = NO;
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished    context:(void *)context {
    NSLog(@"animationDidStop called:shouldContinue = %u",shouldContinue);
    if (shouldContinue) {
        [self startAnimation];
    }
}

But the result is that the text "startAnimation called:shouldContinue = 1" is printed again and again quickly after one round before cancelAnimation being called.It seems as if while(YES) { print(,,,); } a dead loop heppens.


Remove this line from animation code.. [UIView commitAnimations]; It will repeat animation...


please specify that code

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished    context:(void *)context
{
    NSLog(@"animationDidStop called:shouldContinue = %u",shouldContinue);

    if (shouldContinue!=NO) {
        [self startAnimation];
    }
}

please make shouldContinue to ivar if not

if you make shouldContinue as ivar then make sure to specify

self.shouldContinue = NO;

and you didn't call cancelanimation function anywhere, if not then at the end of the startanimating specity that

self.shouldContinue = NO;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜