gpt4 book ai didi

iphone - 重新启动应用程序时 CABasicAnimation 停止

转载 作者:行者123 更新时间:2023-12-03 19:23:01 27 4
gpt4 key购买 nike

我遇到了一个问题:重新启动 iPhone 应用程序会导致动画停止。更具体地说,我设置并运行以下动画:

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

当我按下主页键(iOS 4,因此它仍在后台“运行”)然后重新启动程序时,动画停止了。有什么方法可以防止这种情况或轻松重新启动它们吗?

最佳答案

应用程序委托(delegate)中有两种方法,您可以将信息传递给正在执行动画的 View Controller 。

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

当然,这意味着您需要引用在应用程序委托(delegate)中执行动画的 View Controller ,或者您可以使用通知来传递通知。无论如何,底线是您必须注意应用程序再次激活并重新启动动画。

关于iphone - 重新启动应用程序时 CABasicAnimation 停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3854799/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com