【发布时间】:2023-03-14 10:00:02
【问题描述】:
由于某种原因,我不得不再次提交相同的动画。
- (void)startAnimation {
NSLog(@"startAnimation called:shouldContinue = %u",shouldContinue);
shouldContinue = YES;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: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];
}
}
但结果是,在调用cancelAnimation之前的一轮之后,文本“startAnimation called:shouldContinue = 1”被一次又一次快速打印出来。看起来好像while(YES) { print(,,,); } 出现死循环。
【问题讨论】:
标签: iphone objective-c animation uiview