ohh*_*hho 8 interface-builder ios autolayout
要UIView像这样支持纵向和横向:
+-------------------+
| +---------------+ |
| | | |
| | Fixed | |
| | size | |
| | Square | |
| | | |
| +---------------+ | Protrait
| +---------------+ |
| | Flexible C | |
| +---------------+ |
| +---+ +---+ |
| | A | | B | |
| +---+ +---+ |
+-------------------+
+----------------------------------+
| +---------------+ +------------+ |
| | | | Flexible | |
| | Fixed | | C | |
| | size | +------------+ |
| | Square | +---+ +---+ |
| | | | A | | B | |
| +---------------+ +---+ +---+ |
+----------------------------------+
Horizontal
Run Code Online (Sandbox Code Playgroud)
我是否需要手动重新定位子视图willRotateToInterfaceOrientation?或者可以Autolayout自动为我做?
B 按钮始终位于右下方 A是一个相对于B(最好与左侧对齐C)定位的按钮C 用于文字,大小灵活A并B在下面C在这种情况下,您应该能够自动完成大部分布局工作,但在旋转时稍微调整一下.
我的建议是要包含的观点A,B和C的另一个UIView.这样,取决于方向的布局与灵活大小的布局是分开的.它还使编码更简单!
然后你布局方形视图和容器视图有点像这样:
H:|-10-[squareView]
V:|-10-[squareView]
H:[containerView]-10-|
V:[containerView]-10-|
squareView.width == squareView.height
Run Code Online (Sandbox Code Playgroud)
请注意,方形视图始终与超视图的左侧和顶部对齐,而容器视图与底部和右侧对齐.对于纵向方向,您可以添加以下约束:
V:[squareView]-10-[containerView]
H:[squareView]-10-|
H:|-10-[containerView]
Run Code Online (Sandbox Code Playgroud)
对于横向方向,您可以反转这些约束:
H:[squareView]-10-[containerView]
V:[squareView]-10-|
V:|-10-[containerView]
Run Code Online (Sandbox Code Playgroud)
这仅适用于整体布局,因此容器视图的子视图的灵活大小由您决定.希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
158 次 |
| 最近记录: |