iPhone X与iOS11适配

2017-09-25  本文已影响24人  最晴天

总有小伙伴什么资料都不查找翻看,就问我X的适配是怎么做的,每一次都表示深深的无力。。。。

简单总结了一下,因某项目简单,除了启动图外,实际上需要额外注意的只有两点:
1.safeAreaInsets问题
2.scrollView、tableView问题

在navigationController.navigationBar.prefersLargeTitles未开启的情况下,
iPhone X的状态栏高度为44,外加navBar高度44,合计88pt,而底部的安全区域高度为34pt.
而prefersLargeTitles开启时,safeAreaInsets的值为{140, 0, 34, 0}。
在现有iPhone机型中,X的高度特殊,所以我使用了屏幕高度来判断是否是X,也可以通过这篇文章中的方式来判断机型:
https://www.jianshu.com/p/02bba9419df8
某些宏定义,便于简便使用

#define HHTopbarTotalHeight ([[UIApplication sharedApplication] statusBarFrame].size.height+44)

#define HHSafeAreaBottomHeight ({CGFloat i; if(@available(iOS 11.0, *)) {i = HHKeyWindow.safeAreaInsets.bottom;} else {i = 0;} i;})

#define HHNormalAvaliableHeight (HHMainScreenHeight-HHSafeAreaBottomHeight-HHTopbarTotalHeight)

#define HHiPhoneX (HHMainScreenHeight == 812)
#define HHMainScreenWidth [UIScreen mainScreen].bounds.size.width
#define HHMainScreenHeight [UIScreen mainScreen].bounds.size.height
#define HHMainScreenBounds [UIScreen mainScreen].bound

这篇文章写的很详细哦:
https://www.jianshu.com/p/3a9ad4f0fa32
参考文章:
iPhone X 的 UI界面适配官方指南https://juejin.im/entry/59b938f86fb9a00a5c3c32df
关于iPhone X 的适配 http://m.blog.csdn.net/wujakf/article/details/78043586
iOS11 & iPhone X 适配指南

上一篇下一篇

猜你喜欢

热点阅读