How to detect a core animation is skipped / failed to start
In my game, I have a series of core animation running one after another within split of a second. At the end of the animations, a method is invoked to triggered (animationDidStop:) some important logic.
Usually this works well开发者_运维知识库. However, occasionally, specially on slower device such as iPhone 3G or iPhone 2, one of the animations is skipped (or failed to start) due to timing issue (too much stuff running and the CPU can't catchup). I am fine with skipping animations, but the problem is, my method is not invoked either. It will be nice if such skipping can be detected.
Anybody knows how to detect the case when a core animation is skipped/failed to start?
thanks.
You need to use 2 things for that
- NSTimer* timer
- BOOL isAnimationCompleted
1) Start a timer "timer" of same time as animation time.
2) set "isAnimationCompleted = TRUE" in (animationDidStop:) method
3) after "timer" ticks check for the "isAnimationCompleted" variable
if(!isAnimationCompleted)
[self callMethodMannually];
I'm sure there's a better option I don't see but you could always save the state in some variable then use an NSTimer to fire off a task which later checks that state.
Hopefully someone else comes up with something a bit less hacky for you!
精彩评论