applicationWillTerminate 被延迟,退出时是否有更快的方法可以使用?

发布于 2024-08-04 10:56:33 字数 349 浏览 9 评论 0原文

我正在使用 - (void)applicationWillTerminate:(NSNotification *)notification 在游戏退出时保存数据,然后在用户下次按下加载按钮时加载它。保存和加载工作正常,但我注意到按下主页按钮和保存数据之间存在一些滞后。每当我退出、重新启动和加载时,游戏的计时器都会持续计时,并且在调用 applicationWillTerminate 之前状态会发生变化;例如,运动中的游戏对象被加载到与我上次按下主页按钮所看到的不同的位置。有趣的是,如果我快速按下主页按钮......它似乎会退出应用程序,并且弹出音乐控件。然而,如果我每次再次加载数据时都以这种方式退出,计时器就不会继续——游戏对象不会以其速度继续移动。 有办法解决这个问题吗?

I'm using - (void)applicationWillTerminate:(NSNotification *)notification to save data when my game exits, then loading it if the user presses the load button next time around. The saving and loading work fine, but I've noticed there is some lag between when I press the home button and when the data gets saved. Whenever I exit, relaunch and load, the game's timer has kept ticking and states were changing before applicationWillTerminate gets called; e.g. game objects in motion are loaded at different locations then what I last saw pressing the home button. Interestingly enough, if I press the home button rapidly.. it appears to quit the quitting of the application, and the music controls pop up. However, if I quit in this fashion whenever I load the data again, the timer did not continue -- game objects did not keep moving with their velocities.
Is there a way around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟花易冷人易散 2024-08-11 10:56:33

您看过UIApplicationWillResignActiveNotification吗?在“主控制器”或 UIApplication 子类中加载/初始化时,类似于以下内容:

[[NSNotificationCenter defaultCenter] addObserver:self /* or whatever */ selector:@selector(applicationWillTerminate:) name:UIApplicationWillResignActiveNotification object:NULL];

Have you looked at UIApplicationWillResignActiveNotification? Something like the following at load / init time in your 'main controller' or UIApplication subclass:

[[NSNotificationCenter defaultCenter] addObserver:self /* or whatever */ selector:@selector(applicationWillTerminate:) name:UIApplicationWillResignActiveNotification object:NULL];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文