应用程序从后台恢复时活动指示器动画停止

发布于 2024-09-11 13:06:12 字数 675 浏览 4 评论 0原文

我设置了一个活动指示器,当从互联网下载文件时开始旋转。该文件是异步下载的,如果用户将应用程序发送到后台或启动另一个应用程序,它还会请求继续下载。然而,在恢复我的应用程序后,活动指示器不再旋转,即使我没有在代码中停止它。

我设置了一个标志,让我知道活动指示器是否应该旋转,我认为我可以检测应用程序何时进入前台,测试该标志,然后再次启动活动指示器,但没有出现任何逻辑方法当我设置它们时开火。我尝试了以下方法:

- (void)applicationDidBecomeActive:(UIApplication *)application
- (void)applicationWillEnterForeground:(UIApplication *)application
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application

正如我所说,当用户切换回应用程序(或离开它)时,这些方法都不会触发。

我做错了什么?

I've got an activity indicator set up to start spinning when a file is getting downloaded from the internet. The file is downloaded asynchronously, and it also makes a request to continue downloading should the user send the app into the background or start another app. However, upon resuming my app, the activity indicator is no longer spinning, even though I haven't stopped it in code.

I set up a flag to let me know whether the activity indicator should be spinning, and I thought I could detect when the app came to the foreground, test the flag, and start the activity indicator up again, but none of the logical methods appear to fire when I set them up. I've tried the following:

- (void)applicationDidBecomeActive:(UIApplication *)application
- (void)applicationWillEnterForeground:(UIApplication *)application
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application

As I said, none of these methods fire when when the user switches back to the app (or away from it, for that matter).

What am I doing wrong?

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

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

发布评论

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

评论(2

↙厌世 2024-09-18 13:06:12

我的猜测是,您的应用程序在 UI 线程的某个地方陷入了无限循环,永远不允许运行循环继续。这可以解释为什么这些恢复方法永远不会被调用以及为什么旋转器没有动画。

My guess is that your app is stuck in an infinite loop on the UI thread somewhere, never allowing the run loop to continue. This would explain both why those resume methods are never called and why the spinner is not animating.

揪着可爱 2024-09-18 13:06:12

当我处理代码时,问题最终“消失”了;我一直不明白是什么导致了这个问题。艾德,也许你是对的?我只是不知道。

The problem eventually "went away" while I was working with the code; I never figured out what caused the problem. Ed, maybe you were right? I just don't know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文