iPhone X 底部适配
2017-11-09 本文已影响251人
Minoz_min
场景:UIViewController
上添加 UITableView
以下主要讲的是通过storyboard上直接对控件进行约束约束,实现方法有很多种,我一般用以下方法实现:
Xcode 9之前

然后直接在iPhone x上运行,效果图1:

很显然效果不是我想要的,解决方法看图操作:
双击bottom约束

将
Bottom Layout Guide
改成 superView

再运行结果如图2:

完美解决!!!
Xcode9之后
就用Safe Area Layout Guide
替代了原来的Top/Bottom Layout Guide
,前提是最低支持ios 9
版本才能用使用Safe Area Layout Guide
.
选中Main.storyboard
,然后勾选User Safe Area Layout Guide
,就可以将整个storyboard的页面都添加safe area,如下图:

xcode会自动帮我们转换过来,上面约束图1就变成了以下:

运行之后会发现效果跟图1是一样,再重得上面的步骤:
双击bottom约束

将
Safe Area
改成 superView

运行效果就跟图2一样啦!