iPhone 方向布局从单列到双列
我正在尝试在 Interface Builder 中创建一个 UIView,向用户显示两个包含一些文本的框。此 UIView 应支持横向和纵向模式。
当处于纵向时,两个框应水平居中并位于彼此下方。就像下图这样: 肖像模式 http://img176.imageshack.us/img176/5899/screenshot20100403at709.png< /a>
但在横向时,它应该显示两个垂直居中且并排的框。就像下图这样: 横向模式 http://img40.imageshack.us/img40/1669/screenshot20100403at728.png< /a>
是否可以仅使用自动调整大小选项(或任何其他 IB 选项),或者我是否必须在方向更改事件上重新布局代码中的视图?我更愿意只使用 IB。
我尝试锁定顶部框的顶部和左侧边距,并锁定底部框的底部和右侧边距。但问题是,为了让它工作,我还需要在一个从纵向变为横向时缩小两个盒子,因为否则它们会重叠。
I am trying to create a UIView in Interface Builder that shows to the user two boxes containing some text. This UIView should support both landscape and portrait modes.
When in portrait orientation, the two boxes should be centered horizontally and be under each other. Like in the picture below:
Portrait Mode http://img176.imageshack.us/img176/5899/screenshot20100403at709.png
But when in landscape orientation, it should show the two boxes centered vertically and by side by side. Like in the picture below:
Landscape Mode http://img40.imageshack.us/img40/1669/screenshot20100403at728.png
Is this possible using only the autosizing options (or any other IB options), or do I have to relayout the view in code on orientation change events? I would prefer using only IB.
I tried locking the top and left margins of the top box and locking the bottom and right margins of the bottom box. But the problem is that for it to work I also need to shrink the two boxes as one changes from portrait to landscape, because otherwise they would overlap.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会制作两个视图并使用相同的模型。我发现这极大地简化了我的代码。但是,如果您坚持使用一种视图,只需将它们轮流放置即可。
I would make two views and use the same model. I find this greatly simplifies my code. However if you insist on one view, just lay them out on rotation.
我以前做过类似的事情..
我所做的是通过代码完成的..
在 willRotateToInterfaceOrientation:duration: 方法调用上,我将重新绘制视图的中心点..
它对我有用:)
i did something like this previously..
what i did was done by codes..
on willRotateToInterfaceOrientation:duration: method call, i will replot the center points of the view..
it works for me :)