在从后台恢复时呈现 ModalViewController,避免下面的内容闪烁 [英] Presenting ModalViewController on resume from background, avoiding flash of content underneath

查看:21
本文介绍了在从后台恢复时呈现 ModalViewController,避免下面的内容闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我在启动时以及从后台恢复以呈现加载/摘要屏幕时在根视图控制器顶部呈现一个模态视图控制器.这在几秒钟后被解除以显示根视图控制器.模态通过应用委托上的 applicationWillEnterForeground 方法呈现.

In my application I am presenting a modal view controller on top of the root view controller on launch and also when resuming from the background to present a loading/summary screen. This is dismissed after a few seconds to reveal the root view controller. The modal is presented via the applicationWillEnterForeground method on the app delegate.

一切正常,但是当从后台恢复时,在再次呈现加载模式之前看到下部根视图控制器的闪烁是很常见的.

It's all working fine, but when resuming from the background it's quite common to see a flash of the lower root view controller before the loading modal is presented again.

我正在努力寻找一种明显的方法来进行此演示,以确保它安全地出现而无需先看到下面的视图.我是否遗漏了一些显而易见的东西?

I'm struggling to find an obvious way to do this presentation to ensure it safely appears without seeing the view underneath first. Am I missing something blindingly obvious?

推荐答案

文档 说明如下:

准备拍照.当applicationDidEnterBackground: 方法返回,系统取一个应用程序用户界面的图片,并将生成的图像用于过渡动画.如果您的界面中的任何视图包含敏感信息,您应该先隐藏或修改这些视图applicationDidEnterBackground: 方法返回.

Prepare to have their picture taken. When the applicationDidEnterBackground: method returns, the system takes a picture of your app’s user interface and uses the resulting image for transition animations. If any views in your interface contain sensitive information, you should hide or modify those views before the applicationDidEnterBackground: method returns.

这意味着您应该修改 applicationDidEnterBackground: 中的视图,使其按照您希望的方式出现在应用程序进入后台状态时 iOS 将自动拍摄的图片中.

This means you should modify the view in applicationDidEnterBackground: to have it the way you want it to appear in the picture that iOS will take automatically when an App enters the background state.

还要记住以下几点:

您的应用程序委托的 applicationDidEnterBackground: 方法具有大约 5 秒完成任何任务并返回.在实践中,此方法应尽快返回.如果该方法确实在时间用完之前不返回,您的应用程序将被杀死并从中清除记忆.如果您仍然需要更多时间来执行任务,请致电beginBackgroundTaskWithExpirationHandler:请求背景的方法执行时间,然后在辅助节点中启动任何长时间运行的任务线.无论您是否启动任何后台任务,applicationDidEnterBackground:方法必须仍然在 5 内退出秒.

Your app delegate’s applicationDidEnterBackground: method has approximately 5 seconds to finish any tasks and return. In practice, this method should return as quickly as possible. If the method does not return before time runs out, your app is killed and purged from memory. If you still need more time to perform tasks, call the beginBackgroundTaskWithExpirationHandler: method to request background execution time and then start any long-running tasks in a secondary thread. Regardless of whether you start any background tasks, the applicationDidEnterBackground: method must still exit within 5 seconds.

这篇关于在从后台恢复时呈现 ModalViewController,避免下面的内容闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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