I am running into a problem where a restart of my iPhone app causes animations to stop. More specifically, I have the following animation set and running:
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 it is still ‘running’ in the background) and then relaunch the program, the animation has stopped. Is there any way to prevent this or easily restart them?
There are two methods in your app delegate where you can pass down information to your view controller that is performing the animation.
Of course this means you’ll need a reference to your view controller that is performing the animation in your app delegate, or you could use notifications to pass the notification along. Anyhow, the bottom line is you’ll have to watch for the app becoming active again and restart the animation.