iPhoneX 适配
参考:
- https://developer.apple.com/videos/play/tech-talks/201/
- https://developer.apple.com/videos/play/tech-talks/207/
- https://medium.com/rosberryapps/ios-safe-area-ca10e919526f
- https://medium.com/@kahseng.lee123/how-to-solve-the-most-common-interface-problems-when-adapting-apps-ui-for-iphone-x-44c0f3c80d84
参数:
lck_safeAreaLayoutGuide
: Snap 中使用
lck_safeAreaInsets
: Frame 布局中使用, 在 layoutSubview 时生效
lck_keyWindowSafeAreaInsets
: Frame 布局中使用,全局生效
1. 适配 UITableView(UIScrollView/UICollection)
_tableView.snp.makeConstraints { (make) in
make.leading.trailing.top.bottom.equalTo(0)
}
不需要做额外适配,在 contentInsetAdjustmentBehavior = .automatic
情况下 contentOffSet
会自动适配 Home Indicator
2. 适配自定义控件
// 定义 containerView
let containerView = UIView()
containerView.backgroundColor = _switchView.backgroundColor
addSubview(containerView)
containerView.snp.makeConstraints { (make) in
make.leading.trailing.bottom.equalTo(0)
}
// 适配 safeArea
containerView.addSubview(_switchView)
_switchView.snp.makeConstraints { (make) in
make.leading.trailing.top.equalTo(0)
make.height.equalTo(44)
make.bottom.equalTo(lck_safeAreaLayoutGuide)
}
3.未适配
self.navigationItem.searchController = searchController
因为导航栏底部分割线自定义存在问题
4.其他
left & leading
: leading
布局与 local 有关,一些国家阅读习惯是从右往左, leading 会自动适配, 而 left
是绝对布局
网友评论