gpt4 book ai didi

iphone - 为什么当我的应用程序转到后台时,我的无限期 UIView 动画会停止?

转载 作者:行者123 更新时间:2023-12-03 20:23:41 25 4
gpt4 key购买 nike

我使用以下代码无限期地对 UIView 进行动画处理:

#define DEFAULT_ANIM_SPPED 0.6
#define INFINATE_VALUE 1e100f

[UIView beginAnimations:nil context:nil];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:INFINATE_VALUE];
[UIView setAnimationDuration:DEFAULT_ANIM_SPPED];
CGRect tempFrame=myView.frame;
tempFrame.origin.y -= 30;
myView.frame=tempFrame;
[UIView commitAnimations];

如果我的应用程序转到后台,然后我返回到它,所有像这样的动画现在都会停止。为什么会发生这种情况?

最佳答案

通常,当您的应用程序进入后台时,其执行会完全暂停。即使您的应用程序保持事件状态(出于位置跟踪、VoIP 或其他原因),任何绘制到屏幕上的内容 will be halted当您的应用程序进入后台状态时:

Avoid updating your windows and views. While in the background, your application’s windows and views are not visible, so you should not try to update them. Although creating and manipulating window and view objects in the background does not cause your application to be terminated, this work should be postponed until your application moves to the foreground.

事实上,如果您尝试在后台绘制 OpenGL ES 上下文,您的应用程序will immediately crash :

Do not make any OpenGL ES calls from your code. You must not create an EAGLContext object or issue any OpenGL ES drawing commands of any kind while running in the background. Using these calls causes your application to be terminated immediately.

通常,建议暂停应用程序移动到后台时的所有动画,然后在应用程序位于前台时恢复这些动画。这可以在 -applicationDidEnterBackground: 中处理和-applicationWillEnterForeground:委托(delegate)方法,或者通过监听UIApplicationDidEnterBackgroundNotificationUIApplicationWillEnterForegroundNotification通知。

关于iphone - 为什么当我的应用程序转到后台时,我的无限期 UIView 动画会停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4668714/

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