问题如下:
我的应用程序可以用密码保护。当用户按下主页按钮时,应用程序退出非事件状态。重新打开后,应用程序显示“输入密码”屏幕。但在它出现之前,初始内容屏幕会显示片刻。此外,如果在按下主页按钮后,用户进入预览模式(双击主页按钮),预览显示内容屏幕,而不是密码屏幕。
所以这里有两个问题:
- 如何在应用程序退出之前更改 UI(更改为密码屏幕或某些占位符),以便在预览模式下用户可以看到内容屏幕以外的内容。
- 当应用程序再次激活时,如何让应用程序暂时不显示内容屏幕(在密码屏幕之前)。
如有任何帮助,我们将不胜感激。
来自iOS App Programming Guide
What to Do When Moving to the Background
Apps can use their applicationDidEnterBackground: method to prepare
for moving to the background state. When moving to the background, all
apps should do 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.
因此,在您的 applicationDidEnterBackground
方法中,您应该隐藏您的主视图并显示您的“登录” View 。
更新 经过更多研究后,事实证明您无法呈现 View Controller - 您只能影响根窗口。我已经测试了这个答案中的解决方案 - Display a view or splash screen before applicationDidEnterBackground (to avoid active view screenshot)它有效 - 因此您可以创建一个图像来显示您的登录屏幕并将其放在 UI 的顶部。