iOS 8中的UISplitViewController状态恢复 [英] UISplitViewController state restoration in iOS 8

查看:104
本文介绍了iOS 8中的UISplitViewController状态恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 8上,UISplitViewController似乎保存并恢复其子视图的状态,例如,是否隐藏主视图。

On iOS 8, UISplitViewController appears to save and restore the state of its subviews, for example, whether the master view is hidden or not.

这是不可取的,因为我的应用程序应始终在横向显示主视图,并始终将其隐藏在纵向中。如果用户以横向关闭应用程序(保存横向状态)并以纵向重新打开(横向状态已恢复),则UISplitViewController将以错误的配置显示主视图。

This is undesirable because my app should always show the master view in landscape and always hide it in portrait. If the user closes the app in landscape (landscape state is saved) and reopens it in portrait (landscape state is restored), then the UISplitViewController shows the master view in the wrong configuration.

我仍然需要为UISplitViewController提供恢复标识符,以便子视图控制器保存和恢复自己的状态。那么如何防止UISplitViewController恢复自己的状态,或者如何覆盖这种行为呢?

I still need to supply a restoration identifier to the UISplitViewController so that is subview controllers have their own state saved and restored. So how does one prevent UISplitViewController from restoring its own state, or override this behavior?

推荐答案

我通过继承UISplitViewController并覆盖它来解决这个问题 - (void)decodeRestorableStateWithCoder:(NSCoder *)编码器什么都不做。这样,拆分视图控制器没有机会恢复其视图,但其子视图控制器仍然参与状态恢复。

I solved this by subclassing UISplitViewController and overriding - (void)decodeRestorableStateWithCoder:(NSCoder *)coder to do nothing. This way the split view controller does not have an opportunity to restore its views, but its child view controllers still participate in state restoration.

这篇关于iOS 8中的UISplitViewController状态恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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