如何将 iPad 视图分解为更易于管理的块?
我知道我可能会因为没有正确阅读 HIG 或一些文档而受到指责,但在观看了几个培训视频并在 iPhone 上构建了许多小项目之后,我现在正尝试在 iPad 上将东西组合在一起而且,好吧,我的大脑很痛。
我理解 iPhone 上的想法:一个视图 = 一个屏幕,一个视图 = 一个视图控制器。但现在我正在处理一个可以同时显示多个内容的硬件,我真的不明白我应该如何使用它。
我给出的例子是我当前正在进行的项目...我已经为不同的内容屏幕(启动屏幕、菜单、文章视图等)组合了一堆不同的视图控制器。但随后一些屏幕共享了内容。例如,菜单和文章屏幕都有一个菜单栏(如工具栏),它从屏幕顶部向下滑动并提供导航。另外,我有一个导航元素,应该从屏幕底部向上滑动以导航到不同的文章。这些是我在许多其他 iPad 应用程序中看到的东西(《Wired》就是一个例子)。
但我不应该一次在屏幕上放置多个视图控制器,不是吗?不仅如此,如果我这样做,那么自动旋转功能就会开始变得有点疯狂。但是,如果我将所有内容放入单个屏幕的一个视图控制器中,我最终会得到 1,000 行代码,其中大部分代码需要复制粘贴到其他视图控制器中。对我来说这似乎是一个非常丑陋的解决方案。
所以我显然做错了什么......但我应该做什么?即使有人可以指出我应该阅读的信息的方向,我也会非常感激。
谢谢!
:-乔
I know I'm probably going to be berated for not properly reading the HIG or some documentation, but after going through several training videos and building a number of small projects on the iPhone, I'm now trying to put stuff together on the iPad and, well, my brain hurts.
I understood the idea on the iPhone that one view = one screen and one view = one view controller. But now I'm dealing with a piece of hardware which can show multiple things at once, I don't really understand how I'm supposed to work with it.
The example I'll give is the current project I'm on... I've put together a bunch of different view controllers for different screens of content (splash screen, menu, article view etc). But then some of the screens have shared content. For example, the menu and the article screens both have a menu bar (like a toolbar) which slides down from the top of the screen and provides navigation. Also, I have a navigation element which is supposed to slide up from the bottom of the screen to navigate to different articles. These are things I've seen in many other iPad apps (Wired is an example).
But I'm not supposed to put more than one view controller on the screen at a time, am I? Not only that, but if I do then the autorotate functionality starts going a bit mental. But if I put everything into one view controller for one single screen, I end up with 1,000 lines of code, most of which needs to be copy-pasted into other view controllers. Seems like a pretty ugly solution to me.
So I'm obviously doing something wrong... But what should I be doing? Even if someone could please point me in the direction of the information I should be reading, I'd be very grateful.
Thanks!
:-Joe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不禁止您一次显示多个视图,其中视图控制器只是驻留在内存中的视图管理器。
您可以创建自定义视图控制器来管理您的视图控制器。将其视为 UINavigationController 或 UISplitViewController。
您有一个 NSMutableArray 的 viewControllers
现在,您可以根据需要在屏幕上拥有任意数量的视图及其自己的视图控制器。您可能有嵌套视图控制器,例如:
ViewControllerManager->NavigationController->[ViewControllers];
PS 当然,完整的实现会更复杂,您需要调用视图控制器 viewWill/viewDid、管理视图控制器视图动画(呈现和消除)、lowMemoryWarning 的内存管理(清除不可见或未使用的视图控制器)等等。
希望能有所帮助。 :)
You are not forbidden to display more then one view at a time, where view controllers are just view managers residing is memory.
You can create a custom view controller to manage your view controllers. Think of it as UINavigationController or UISplitViewController.
You have an NSMutableArray of viewControllers
Now you can have as many views with their own view controllers on the screen as you need. You might have nested view controllers for example:
ViewControllerManager->NavigationController->[ViewControllers];
P.S. A full implementation will be more complex of course, you will need to call viewcontrollers viewWill/viewDid, manage viewcontroller view animations (presenting and dismissing), memory management on lowMemoryWarning (purging non visible or not used view controllers) and more.
Hope that helps a bit. :)
我认为您缺少的是您可能会混淆哪些不是 UIViewController。你说得很对,UIKit 希望你一次只显示一个 UIViewController(Apple 的容器视图控制器除外)。然而,单个视图控制器可以管理许多视图的层次结构,每个视图可能有一个控制器对象来管理它们的一些行为。然后,您可以在多个视图控制器中重用这些控制器或自定义视图。
I think that what you are missing is that you can have confounded which are not UIViewControllers. You are quite right that UIKit expects you to display only a single UIViewController at a time (with an exception for Apple's container view controllers). However that single view controller can manage a heirarchy of many views, each of which might have a controller object managing some of their behavior. You can then reuse those controllers or custom views across many view controllers.