在 applicationWillEnterForeground 之前更改视图 [英] Alter view before applicationWillEnterForeground

查看:11
本文介绍了在 applicationWillEnterForeground 之前更改视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在后台运行一段时间后将用户锁定在我的应用程序之外.我在 AppDelegate 的 applicationWillEnterForeground 中发现了这一点(并与存储在 applicationWillResignActive 中的时间进行比较).如果小于超时时间,则不会发生任何操作.如果超过我调用的超时时间:

I want to lock users out of my app after a period of being in the background. I'm catching this in the the AppDelegate's applicationWillEnterForeground (and comparing to time stored in applicationWillResignActive). If less than the timeout period no action takes place. If more than the timeout period I call:

[_navigationController popToRootViewControllerAnimated:NO];

将用户带回根视图.

它在一个视觉中断的情况下工作得非常好.先前的视图(当应用程序处于非活动状态时用户正在查看的视图)在弹出到 root 之前非常短暂地出现.在测试中,视图似乎在 applicationWillEnterForeground 被调用之前重新出现.

It works perfectly fine with one visual interruption. The prior view (that which the user was viewing when the application went inactive) appears very briefly before popping to root. In testing it seems the view reappears prior to applicationWillEnterForeground being called.

我唯一的想法是在进入非活动状态之前隐藏所有内容,例如用实心矩形遮挡视图.这对我来说就像一个肮脏的黑客,所以我认为有更好的方法.

The only thought I've had is to hide everything before going inactive, such as by obscuring the view with a filled rectangle. This smells like a dirty hack to me, so I'm thinking there's a better way.

我也乐于接受不同的方式来达到相同的最终结果.谢谢!

I'm also open to different ways to reach the same end result. Thank you!

推荐答案

来自文档:处理应用状态转换的策略

准备应用快照

应用委托的 applicationDidEnterBackground: 方法返回后不久,系统会拍摄应用窗口的快照.类似地,当应用程序被唤醒以执行后台任务时,系统可能会拍摄新快照以反映任何相关更改.例如,当一个应用程序被唤醒以处理下载的项目时,系统会拍摄一个新的快照,以便能够反映由项目合并引起的任何变化.系统在多任务界面中使用这些快照图像来显示您的应用的状态.

Shortly after an app delegate’s applicationDidEnterBackground: method returns, the system takes a snapshot of the app’s windows. Similarly, when an app is woken up to perform background tasks, the system may take a new snapshot to reflect any relevant changes. For example, when an app is woken to process downloaded items, the system takes a new snapshot so that can reflect any changes caused by the incorporation of the items. The system uses these snapshot images in the multitasking UI to show the state of your app.

如果您在进入后台时对视图进行了更改,则可以调用主视图的 snapshotViewAfterScreenUpdates: 方法来强制呈现这些更改.在视图上调用 setNeedsDisplay 方法对快照无效,因为快照是在下一个绘制周期之前拍摄的,从而防止呈现任何更改.调用值为 YES 的 snapshotViewAfterScreenUpdates: 方法会强制立即更新快照机制使用的底层缓冲区.

If you make changes to your views upon entering the background, you can call the snapshotViewAfterScreenUpdates: method of your main view to force those changes to be rendered. Calling the setNeedsDisplay method on a view is ineffective for snapshots because the snapshot is taken before the next drawing cycle, thus preventing any changes from being rendered. Calling the snapshotViewAfterScreenUpdates: method with a value of YES forces an immediate update to the underlying buffers that the snapshot machinery uses.

这篇关于在 applicationWillEnterForeground 之前更改视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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