在 iPhone 中保持应用程序的布局处于纵向和横向模式
我的应用程序中有一个视图,它具有三个分段按钮控制器,并且我用纵向模式设计了它。当我旋转屏幕时,整个用户界面......就是不正确。
我的问题是,我应该分别针对纵向和横向模式进行设计吗?如果是这样我该怎么做?
附注实际上,我不需要 iPhone 应用程序的旋转支持,但我计划为 iPad 制作相同的应用程序,其中每个视图都必须可旋转。谢谢。
编辑: 刚刚找到了很好的例子 支持多个方向的最简单方法?当应用程序处于横向模式时,如何加载自定义 NIB?
I have a view in my app that has three segmentedButtonControllers and I designed it with portrait mode. When I rotate the screen the whole UI is...just not right.
My question is, should I design for both portrait and landscape mode separately? If so how I do that?
ps. Actually I don't need rotation support for iPhone's app but I'm planning to make same app for iPad where every view has to be rotatable.thanks.
Edit:
just found good example
Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想说这取决于内容。有时,在 Interface Builder 的检查器中正确设置 UI 元素的自动调整大小就足够了,并且您可以获得令人满意的效果,但在某些情况下,仅调整视图大小并不能充分利用屏幕空间。例如,在您的情况下,仅将分段控件扩展到整个宽度可能不如将它们排列在一起以在底部放置文本来得好。
如果您要分别设计这两种模式,则可以将它们作为不同的视图并在相应的视图之间进行切换。很好的例子可以在 iPhone Cookbook 的第 4 章中找到。作者所做的是当方向改变时切换视图,如下所示:
I'd say it depends on the content. Sometimes it's enough to set the autoresizing of the UI elements in the Inspector of the Interface Builder properly and you get a satisfying effect, but there are cases where just resizing the view doesn't make the best use of the screen real estate. In your case for example just extending the segmented controls to the full width is probably not going to be as nice as arranging them next to each other to make the place for the text at the bottom.
If you are going to design for both modes separately, you can have them as different views and switch between the accordingly. Good example can be found in the 4th chapter of iPhone Cookbook. What the author does there is to switch the view when the orientation changes as follows :
我强烈建议您在文档中查找 UIViewController 类并阅读全部内容(假设您还没有)。您需要的关键方法包括
willRotateToInterfaceOrientation:duration:
,描述如下:willRotateToInterfaceOrientation:duration:
在用户界面开始旋转之前发送到视图控制器。
听起来您还应该包括:
I strongly recommend you look up the
UIViewController
class in docs and read it all (assuming you haven't already). The key methods you need includewillRotateToInterfaceOrientation:duration:
, described as follows:willRotateToInterfaceOrientation:duration:
Sent to the view controller just before the user interface begins rotating.
It sounds like you should also include:
只需将控件的
autoresizingMask
属性设置为Just set the
autoresizingMask
property of your control to我一直在寻找解决方案,最后选择以编程方式设置布局元素,如 这篇文章。
I was looking for a solution and finally have chosen to set the layout elements programatically, as described in this article.