iPhoneX+ 适配

2019-03-17  本文已影响0人  切一斤桃花卖酒钱

iPhoneX 适配

参考:

  1. https://developer.apple.com/videos/play/tech-talks/201/
  2. https://developer.apple.com/videos/play/tech-talks/207/
  3. https://medium.com/rosberryapps/ios-safe-area-ca10e919526f
  4. 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 是绝对布局

上一篇 下一篇

猜你喜欢

热点阅读