在IB中处理景观/肖像差异的最好方法是什么? [英] What's the best way to handle landscape/portrait differences in IB?

查看:119
本文介绍了在IB中处理景观/肖像差异的最好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图支持横向和纵向查看,当您从一个切换到另一个时,控件都移动。我目前这样做通过设置我的每个控件的.center当用户旋转手机。问题是,这是单调乏味,需要大量的代码,似乎打败了使用Interface Builder的第一个目的。

I have a view that supports landscape and portrait viewing, with the controls all moving around when you switch from one to the other. I'm currently doing this by setting the .center of each one of my controls when the user rotates the phone. The problem is that this is tedious, and requires a lot of code, and seems to defeat the purpose of using Interface Builder in the first place.

我的问题是:有一种方法在Interface Builder中为一个视图支持多个外观(一个用于风景一的肖像)?如果不是其他人怎么做这与IB?你设置了2个视图?

My question is: is there a way in Interface Builder for one view to support multiple looks (one for landscape one for portrait)? If not how do other people do this with IB? Do you set up 2 views?

编辑:为了澄清我的风景和肖像视图看起来不同,我不想直接变换,我实际上显示的数据不同在横向模式中

Just to clarify my landscape and portrait views look different, I don't want a straight transform, I actually display the data differently in landscape mode

推荐答案

必要时,我将 UIView 在我隐藏的IB。给它一个很好的背景颜色,所以你可以看到它,并将它一路送到背景。然后,当需要设置对象的框架时,使用该视图的框架。如果你有很多,你可以考虑使用 UILabel ,因此你可以在IB中给它一个可见的名字。

When necessary, I add UIView objects to the view in IB which I make hidden. Give it a nice background color so you can see it, and send it all the way to the background. Then use that view's frame when you need to set the frame of an object. If you have a lot of them, you might consider using UILabel instead, so you can give it a visible name in IB.

如果您担心内存问题,只需删除 ViewDidLoad 中的所有这些额外的 UIView 将它们的帧值存储在成员 CGRect 中。这只有当然,如果你没有任何视图自动调整大小或重新定位旋转,这可能是你不应该反正在这种情况下。我这样做是为了任何原因调整大小/重新定位,而不只是当屏幕旋转。

If you're worried about memory issues, just remove all these extra UIViews in ViewDidLoad and just store their frame values in member CGRects. This only works of course if you don't have any of the views auto-resize or reposition on rotate, which you probably shouldn't anyway, in this case. I do this for resizing/repositioning for any reason, not just when the screen rotates.

这篇关于在IB中处理景观/肖像差异的最好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆