要像这样为 UIView
支持纵向和横向:
+-------------------+
| +---------------+ |
| | | |
| | Fixed | |
| | size | |
| | Square | |
| | | |
| +---------------+ | Protrait
| +---------------+ |
| | Flexible C | |
| +---------------+ |
| +---+ +---+ |
| | A | | B | |
| +---+ +---+ |
+-------------------+
+----------------------------------+
| +---------------+ +------------+ |
| | | | Flexible | |
| | Fixed | | C | |
| | size | +------------+ |
| | Square | +---+ +---+ |
| | | | A | | B | |
| +---------------+ +---+ +---+ |
+----------------------------------+
Horizontal
我是否需要手动重新定位 willRotateToInterfaceOrientation
中的 subview ?或者 Autolayout
可以自动为我完成吗?
B
是一个始终位于右下方的按钮A
是相对于B
定位的按钮(最好对齐到C
的左侧)C
为文字,大小灵活A
和B
在C
下面
最佳答案
在这种情况下,您应该能够自动完成大部分布局工作,但需要在旋转时进行一些细微的调整。
我的建议是在另一个UIView
中包含 View A、B 和C。这样,方向相关的布局与灵活大小的布局分开。它还使布局更易于编码!
然后你像这样布置方形 View 和容器 View :
H:|-10-[squareView]
V:|-10-[squareView]
H:[containerView]-10-|
V:[containerView]-10-|
squareView.width == squareView.height
请注意,正方形 View 始终与父 View 的左侧和顶部对齐,而容器 View 始终与底部和右侧对齐。对于纵向,您可以添加以下约束:
V:[squareView]-10-[containerView]
H:[squareView]-10-|
H:|-10-[containerView]
对于横向,您可以反转这些约束:
H:[squareView]-10-[containerView]
V:[squareView]-10-|
V:|-10-[containerView]
这只是针对整体布局,因此容器 View subview 的灵活大小取决于您。希望这对您有所帮助!
关于ios - autolayout 可以自动布局这个(附图)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17960397/