Presenting ModalViewController on resume from back

2019-09-12 21:13发布

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?

2条回答
Juvenile、少年°
2楼-- · 2019-09-12 21:38

The documentation says the following:

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.

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.

Also keep the following in mind:

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.

查看更多
Deceive 欺骗
3楼-- · 2019-09-12 21:52

As I recall, when an app is backgrounds Apple code takes a screenshot and stores it off. When your app is brought back up it displays the screenshot until your app finishes coming up and takes over.

Short answer, I don't think it's possible to avoid the flash of the content.

You really have 2 choices, I would just suggest making a short "appear" animation to make a smooth transition. That wont work if you are trying to protect sensitive material with a relogin prompt or something though. If you are dealing with a situation like that you need to handle things when you enter backound state and not when you ae coming back from it.

查看更多
登录 后发表回答