在重新启动这个应用程序时CABasicAnimation停止 [英] CABasicAnimation stops when relaunching the app

查看:160
本文介绍了在重新启动这个应用程序时CABasicAnimation停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了我在这里的iPhone应用程序的重新启动造成的动画停止了问题。更具体地讲,我有以下的动画设置和运行:

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"];

当我preSS Home键(iOS 4的所以它仍然在后台运行),然后重新启动该程序中,动画已停止。有没有什么办法prevent这样或轻松地重新开始呢?

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.

- (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 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.

这篇关于在重新启动这个应用程序时CABasicAnimation停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆