iPhone X 适配
iPhone X 基本信息
NavigationBar(包含状态栏)
Large Title : Bar高度为140 Point
Normal Title: Bar高度88 Point
iOS 11引入新API
- additionalSafeAreaInsets
这是VIewController的属性,开发者可以改变Safe Area insets,来修改Safe Area的区域。
注意如果viewController是在一个NavigationController中,那么应该先改变NavigationController的additionalSafeAreaInsets,在改变viewController的additionalSafeAreaInsets。如嵌套比较深的:
// self是tabViewController中的NavigationController中的一个ViewController
self.tabBarController.additionalSafeAreaInsets = UIEdgeInsetsMake(-20, 0, 0, 0);
self.navigationController.additionalSafeAreaInsets = UIEdgeInsetsMake(-20, 0, 0, 0);
self.additionalSafeAreaInsets = UIEdgeInsetsMake(-20, 0, 0, 0);
Safe Area
- IB中约束:勾选 Use Safe Area Layout Guides 属性。
[image:FF8309A9-8964-4436-84F5-6452F7666F01-13446-0001D5BE6C788F7C/412CD298-1A85-4132-BA28-F745AF207B2C.png]
IB中的约束应该相对于 Safe Area 建立。 - 代码中约束: UIView 有个属性 UILayoutGuide safeAreaLayoutGuide,使用 Masonry 布局更简洁。
Masonry bug: 当前Masonry最新版本为1.1.0,9.20号发布。mas_safeAreaLayoutGuide 实际是 mas_safeAreaLayoutGuideBottom。10.17修复了此bug但是并未发布新版本。
Fully supports iOS 11 safeAreaLayoutGuide, and fix #470
v 1.1.0 safeAreaLayoutGuide Crsah · Issue #477 · SnapKit/Masonry · GitHub
IB自定义假NavigationBar
customNavBarView 的 top leading trailing 与 superView建立约束, customNavBarView的bottom与Safe Area.Top 建立 -44 约束。即可让customNavBarView高度适配iPhone X与普通设备。
Tips
- tab bar push 时会出现上移的问题。截止iOS 11.1 应该是苹果系统bug。 ios - Why page Push animation Tabbar moving up in the iPhone X - Stack Overflow