objective-c - 模态视图 Controller 是替代 iPad 上整个界面的首选方式吗?

标签 objective-c cocoa-touch ipad uiviewcontroller ios

具体来说,我有一个类似游戏的东西,带有由标准组件制成的菜单屏幕。我想要一个按钮切换到用户将与之交互一段时间的另一个 View Controller ,然后返回到菜单屏幕。似乎让菜单 Controller 将“游戏”模式呈现为模态视图 Controller 是最直接的解决方案,但这是否是本质上替换整个 View 的最佳方法?只要模态 Controller 在前面,整个菜单(以后可能会成为深层导航或拆分 Controller )是否会保留在内存中,这是我应该费心担心的事情吗?

最佳答案

这个问题实际上有两个部分:

在 iPad 应用程序中从一个 View 转换到下一个 View 的哪种方法可以为用户提供最佳体验?

哪种从一个 View 转换到下一个 View 的方法最容易实现并且最好地处理内存管理?

除了向您指出 Apple 的“iPad 人机界面指南”之外,我不会尝试解决此问题的第一部分,其中(除其他外)指出:

Reduce Full-Screen Transitions

Closely associate visual transitions with the content that’s changing. Instead of swapping in a whole new screen when some embedded information changes, try to update only the areas of the user interface that need it. As a general rule, prefer transitioning individual views and objects, not the screen. In most cases, flipping the entire screen is not recommended.

When you perform fewer full-screen transitions, your application has greater visual stability, which helps people keep track of where they are in their task. You can use UI elements such as split view and popover to lessen the need for full-screen transitions.

http://developer.apple.com/library/ios/prerelease/#documentation/General/Conceptual/iPadHIG/DesignGuidelines/DesignGuidelines.html

但是,就您的情况而言,我认为全屏转换是完全合适的(但我不是用户体验专家)。

在回答第二部分时,是的,以模态方式显示新的 View Controller 似乎是一个很好的方法。

默认情况下,菜单 View 使用的对象和模态视图使用的对象都将保留在内存中 - 但使用 UIViewController 子类的好处是它们内置了一些默认的内存管理。如果您的应用程序在全屏模式下显示模态视图时收到内存警告,则菜单 View Controller 的 View 将被删除,并且其“viewDidUnload”方法将被调用。因此,在实现此方法时,您应该释放不需要的任何对象,然后根据需要在菜单 View Controller 的 viewDidLoad 方法中重新创建它们(该方法将在显示菜单 View 之前再次调用)。

UIViewController 类引用中对此进行了更详细的解释:

When a low-memory warning occurs, the UIViewController class purges its views if it knows it can reload or recreate them again later. If this happens, it also calls the viewDidUnload method to give your code a chance to relinquish ownership of any objects that are associated with your view hierarchy, including objects loaded with the nib file, objects created in your viewDidLoad method, and objects created lazily at runtime and added to the view hierarchy. Typically, if your view controller contains outlets (properties or raw variables that contain the IBOutlet keyword), you should use the viewDidUnload method to relinquish ownership of those outlets or any other view-related data that you no longer need.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

关于objective-c - 模态视图 Controller 是替代 iPad 上整个界面的首选方式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3623405/

相关文章:

ios - 具有非规则形状的 NSTextContainer 示例?

objective-c - 如何让 iAd 在我的应用程序中被全局查看?

objective-c - 应用程序包中的本地化文件

ios - 有没有办法在ios中动态更改应用程序图标?

objective-c - 为什么有些对象在 objective-c 中使用前不需要初始化?

iphone - dateWithTimeIntervalSince1970 在创建事件时不起作用

ios - 在 iPhone 上阅读资源文本文件

iphone - 我怎样才能改变 UITextview 的内容

objective-c - 在 uilabel 中找到文本的位置 {x,y}

iphone - 在 iPhone 中下载图像时在 UIProgressView 中显示准确的进度