美文网首页
iPhone X 底部适配

iPhone X 底部适配

作者: Minoz_min | 来源:发表于2017-11-09 11:07 被阅读251次

场景:UIViewController 上添加 UITableView

以下主要讲的是通过storyboard上直接对控件进行约束约束,实现方法有很多种,我一般用以下方法实现:

Xcode 9之前

constraint1.png

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


Simulator Screen Shot - iPhone X - 1.png

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

constraints2.png
Bottom Layout Guide 改成 superView
constraints3.png

再运行结果如图2:


Simulator Screen Shot - iPhone X - 2 .png

完美解决!!!

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,如下图:

constraints4.png

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

constraints5.png
运行之后会发现效果跟图1是一样,再重得上面的步骤:
双击bottom约束
constraints6.png
Safe Area 改成 superView
constraints7.png
运行效果就跟图2一样啦!

相关文章

网友评论

      本文标题:iPhone X 底部适配

      本文链接:https://www.haomeiwen.com/subject/dfrpmxtx.html