gpt4 book ai didi

iphone - WillEnterForeground 是否工作不正常?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:48:08 24 4
gpt4 key购买 nike

我的 iOS 应用有一个要求,如果您暂停该应用一段时间(比如一个小时),我们希望该应用返回不是您之前所在的位置,但是到主屏幕。这个想法是你深入到应用程序中,查找一些东西,然后忘记它。一个小时后,当您再次需要该应用时,您之前所做的一切都无关紧要,我们只想在主屏幕上再次自动启动。

我已经用 DidEnterBackgroundWillEnterForeground 实现了它,它几乎完美地工作。当应用程序进入后台时,我会写一个时间戳。当它恢复时,我将时间戳与当前时间进行比较,如果大于 1 小时窗口,我将所有内容从 ViewController 堆栈中弹出,并设置 animation=false,然后我们就回家了。

这适用于 iPad 和所有模拟器,但在我的 iPhone 上,它会在回家前显示前一屏幕几分之一秒,即使 WillEnterForeground 出现在它应该可见之前,它在没有动画的情况下从堆栈中弹出,所以不应该是可见的。这是怎么回事?

最佳答案

这是因为 iOS 会在您的应用程序后台运行之前故意拍摄窗口快照,然后在恢复时显示它,以给人一种更快捷的界面印象。来自 Apple 的文档 here :

When an app transitions to the background, the system takes a snapshot of the app’s main window, which it then presents briefly when transitioning your app back to the foreground. Before returning from your applicationDidEnterBackground: method, you should hide or obscure passwords and other sensitive personal information that might be captured as part of the snapshot.

所以答案是删除或以某种方式清空 applicationDidEnterBackground 中的 View (例如,将 Root View 的 alpha 设置为 0.0),这样您就可以决定是否应该再次显示它.

关于iphone - WillEnterForeground 是否工作不正常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17094853/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com