使用3.5和4英寸外形尺寸的自动布局调整视图大小

问题描述:

我有一个原型tableview单元格,在tableview单元格的自定义视图。包含tableview的视图控制器将只以横向模式显示。目标是在tableview单元格内的UIView基于形状因子调整其宽度。因此,例如左右可能有20pt的间距,然后uiview调整其宽度以填充剩余的空间。我希望这样做与storyboard和autolayout。

I have a prototype tableview cell, with a custom view inside of the tableview cell. The view controller that contains the tableview will only be displayed in landscape mode. The goal is for the UIView that is inside of the tableview cell to resize it's width based on the form factor. So for example there might be a 20pt spacing on the left and right and then the uiview resizes it's width to fill the rest of the space. I'm hoping to do this with storyboard and autolayout.

在3.5英寸的外形中,它看起来像这样(这也是在4英寸模式下应该看起来像)

In 3.5 inch form factor it looks like this (this is what it should look like in 4 inch mode as well)

>

4英寸形状因子看起来像这样(宽度没有自动调整大小)

In 4 inch form factor it looks like this (width didn't auto resize)

我知道这里的'auto layout'是合法的,因为水平空间在4英寸外形上大于20。问题的核心是...如何获得一个子视图自动调整宽度当屏幕的宽度改变使用storyboard / autolayout / constraints?

I understand that the 'auto layout' here is legal, since the horizontal space is >20 on the 4 inch form factor as well. The heart of the question though is... how do I get a subview to autoresize it's width when the width of the screen changes using storyboard/autolayout/constraints?

所有你需要的是以下四个约束来自动调整3.5和4英寸屏幕的单元格视图。

All you need are following four constraints to autosize your cell view for 3.5 and 4 inches screens.

>

Xcode 4.6 界面生成器有一个错误,有时它不适当应用约束切换ViewController大小在3.5和4之间设计时间。但是,它在3.5和4模拟器中打开时工作正常。

Xcode 4.6 Interface Builder has a bug where at times it does not properly apply constraints when switching ViewController size between 3.5" and 4" at design time. However, it works just fine when opened in the 3.5" and 4" simulators.