CABasicAnimation stops when the application restarts.

I ran into a problem when restarting my iPhone application causes the animation to stop. More specifically, I have the following animation set and launch:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"]; animation.duration = 1.0; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; animation.repeatCount = 1e100f; // Infinite animation.autoreverses = YES; animation.fromValue = animationStartPath; animation.toValue = animationFinishPath; [view.layer addAnimation:animation forKey:@"animatePath"]; 

When I press the home key (iOS 4, so that it still "works" in the background), and then restarts the program, the animation stops. Is there a way to prevent this or restart them easily?

+4
source share
1 answer

In application deletion, there are two methods in which you can pass information to the view controller that performs the animation.

 - (void)applicationWillResignActive:(UIApplication *)application { // Make note of whether or not the animation is running. // Using NSUserDefaults is probably the simplest } - (void)applicationDidBecomeActive:(UIApplication *)application { // Check your user default setting to see if the animation // was running when the app resigned active and then restart it } 

Of course, this means that you will need a link to your view controller that performs the animation in your applicationโ€™s application, or you can use notifications to send notifications. In any case, on the bottom line you will have to make sure that the application is activated again and restarts the animation.

+1
source

All Articles