一个 UIViewController 或两个用于纵向/横向视图

发布于 2024-09-16 06:25:02 字数 289 浏览 5 评论 0原文

我正在寻找有关视图控制器和视图的一些说明。一个视图控制器是否应该专门用于控制一个视图?

基本上,我的纵向视图将是一个 4x3 的按钮网格(在滚动视图内)。当我将视图旋转为横向时,我可能需要 6x4 的网格。

显然,处理按钮点击等的功能在任一方向上都是相同的,因此在横向上复制此功能似乎需要付出很大的努力。

我应该如何让视图控制器使用正确的视图 xib?

我应该有两个单独的 xib 吗?我已经尝试了自动调整大小蒙版的每种组合,但运气不佳。

我不确定正确的方法。

谢谢。

I am looking for some clarification with regards to view controllers and views. Should one view controller be used exclusively to control one view?

Basically, my portrait view is going to be a 4x3 grid of buttons (within a scrollview). When i rotate the view to landscape, i am going to want maybe a 6x4 grid.

Obviously the functionality for handling the buttons' clicks etc will be the same in either orientation, so it would seem a lot of effort to duplicate this for landscape.

How should i get the view controller to use the correct view xib?

Should i have two seperate xibs? I have tried every combination of autoresize masks and not having much luck.

I'm not sure of the correct way to go.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鱼忆七猫命九 2024-09-23 06:25:02

我不认为上述回答回答了joec的问题。 joec想知道,拥有2个nib(即landscape.nib和portrait.nib)是坏还是好,并使用1个uiviewcontroller管理这2个nib中的视图。

我对 mvc 设计模式的理解是,ViewController 确实应该管理不同的视图。但是当我查看互联网时,由于可可触摸,人们经常说当 UIViewController 在运行时切换其视图属性时,这是不好的(无论这意味着什么)。这让我很困惑。为什么视图控制器不能切换视图?为什么我应该构建一些奇怪的“主”视图控制器,它管理另外两个视图控制器,并且每个人都管理自己的视图。在横向和纵向抽象(或即 iphone-gui 和 ipad-gui 抽象)的情况下,gui 业务层中的代码(视图控制器中的事件代码等)对于不同的视图是完全相同的。视图的风格不是。这应该是 MVC 实现的好处之一。

抱歉,但这对我来说似乎不合逻辑,苹果。

有什么想法吗?

编辑说:

苹果似乎提供了一些奇怪的解决方法来解决这个问题(讨厌我,但对我来说仅此而已,因为我在 UIViewController 类中没有看到真正直接的设计实现来管理和处理视图):

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html%23//apple_ref/doc/uid/TP40007457-CH101-SW26

我发现了这个以下堆栈溢出线程中的链接:

想要使用 multiple不同 iPhone 界面方向的笔尖

感谢 Michal 的帮助。

i do not think that the above one answered the question of joec. joec want to know, if it is bad or good to have 2 nibs (i.e. landscape.nib and portrait.nib) and manage the views in that 2 nibs with 1 uiviewcontroller.

my understanding of the mvc design pattern is, that a ViewController really SHOULD manage different views. but when i look at the internet, in cause of cocoa touch, often people says that it is BAD (whatever this means) when a UIViewController switches his view-property at runtime. thats confusing to me. why should a viewcontroller not be able to switch views ? why should i build some strange "master"-viewcontroller, which manages 2 other viewcontrollers, and everyone of this manages his own view. in case of landscape and portrait abstraction (or i.e. iphone-gui and ipad-gui abstraction) the code in the gui-business-layer (the event-code etc. in the viewcontroller) is exactly the same for different views. the style of the views is not. so that should one of the benefits of a mvc-implementation.

sorry, but that seems not logical for me, apple.

any thoughts ?

edit says:

it seems that apple provides some strange sort of workaround to solve this problem (hate me, but for me it is nothing more than that, because i see no really straight-forward design implementation for managing and handling views in the UIViewController class):

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html%23//apple_ref/doc/uid/TP40007457-CH101-SW26

i found this link in the following stack overflow thread:

Want to use muliple nibs for different iphone interface orientations

thanks to Michal for that one.

蓬勃野心 2024-09-23 06:25:02

您还可以尝试更改视图和子视图大小等。
看看 Madhup 之前解释过的这里。 在方向更改时更改 UIView

You can also try to change your views and subviews sizes etc.
Take a look here Madhup expained It before. Changing UIView on orientation change

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文