有没有办法可以轻松更改界面方向?
我有 MainWindow.xib 文件,我尝试设计第二个 .xib 文件,即 MainWindowLandscape.xib。我有很多 .xib 文件,我分别为纵向和横向设计它们。
我想在 MainWindow.xib 和 MainWindowLandscape.xib (基于 UITabbarController )中分配它们,我的意思是我将在 MainWindow.xib 中分配纵向视图,在 MainWindowLandscape.xib 中分配横向视图。有可能或者最简单的方法是什么?
所有视图(纵向和横向)彼此都做同样的事情。仅 UI 会发生变化。
多谢。
I have MainWindow.xib file and I try to desing a second .xib file which is MainWindowLandscape.xib. I have many .xib file and I design them separately for Portrait and Landscape.
I want to assign them in MainWindow.xib and MainWindowLandscape.xib ( UITabbarController based ), I mean I will assign portrait views in MainWindow.xib, and landscape views in MainWindowLandscape.xib. Is it possible or what is the easiest way?
All views ( portrait and landscape ) do same thing in each other. Only UI will be change.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过覆盖
与两个 xib 文件关联的视图控制器来做到这一点。
具体来说,如果您想强制方向始终为纵向,请执行以下操作:
当您想强制视图控制器始终以横向显示时:
执行此操作后,您必须记住,仅当控制器满足其发生的条件。具体来说,对于标签栏控制器,所有内部控制器都必须支持给定的方向(即,它们应该像上面一样实现
shouldAutorotateToInterfaceOrientation
)。You can do that by overriding
in the view controllers associated to the two xib files.
Concretely, in case you want to force the orientation to always be portrait, do:
When you want to force your view controller to always show in landscape:
Once you do this, you have to keep in mind that controllers will auto rotate only if they meet the conditions for it to happen. Specifically, for tab bar controllers, all internal controllers must support the given orientation (i.e., they should implement
shouldAutorotateToInterfaceOrientation
like above).