1捅膘、iOS 11之前的導航欄的高度是64px(狀態(tài)條+導航欄)蛔垢,iOS11之后如果設(shè)置了prefersLargeTitles = YES(默認NO)則為96pt狐树。所以一般不用管沟启。
2、在iOS 11上運行tableView向下偏移64px或者20px段审,因為iOS 11廢棄了automaticallyAdjustsScrollViewInsets全蝶,而是給UIScrollView增加了contentInsetAdjustmentBehavior屬性。避免這個坑的方法是要判斷
if?(@available(iOS?11.0,?*))?{
_tableView.contentInsetAdjustmentBehavior?=?UIScrollViewContentInsetAdjustmentNever;
}else?{
self.automaticallyAdjustsScrollViewInsets?=?NO;
}
3寺枉、tableView的sectionHeader抑淫、sectionFooter高度與設(shè)置不符,因為tableView的estimatedRowHeight姥闪、estimatedSectionHeaderHeight丈冬、 estimatedSectionFooterHeight三個高度估算屬性由默認的0變成了UITableViewAutomaticDimension。最簡單的方法就是直接設(shè)置為0甘畅。
4、iPhone X狀態(tài)條由20px變成了44px往弓,UITabBar由49px變成了83px疏唾。設(shè)置布局時y直接寫成64的就要根據(jù)機型設(shè)置『疲可以設(shè)置宏
#define Device_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)槐脏,
然后再設(shè)置。
5.IOS11 之前撇寞,不想讓scrollView偏移64px顿天,設(shè)置automaticallyAdjustsScrollViewInsets=NO就可以了。IOS11以后就廢棄了蔑担,使用scrollView的屬性contentInsetAdjustmentBehavior來防止偏移牌废。
UIScrollViewContentInsetAdjustmentAutomatic
UIScrollViewContentInsetAdjustmentScrollableAxes
UIScrollViewContentInsetAdjustmentNever
UIScrollViewContentInsetAdjustmentAlways
這里我們直接選Never就可以了
這里要注意的是,需要判斷當前系統(tǒng)
//ios11 設(shè)置scrollView偏移
if (@available(iOS 11.0, *)) {
_scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
6.navigation bar 的titleView支持了autolayout啤握,需要titleView自己撐開或者重寫了- intrinsicContentSize方法鸟缕。intrinsicContentSize顧名思義,固定大小的意思排抬,主要是解決一些模糊約束的問題懂从。更多知識可以看這篇文章詳解intrinsicContentSize。
不做適配在IOS11會遇到的問題:
titleView對應的View大小和預期不一致蹲蒲。
titleView對應的View有點擊事件會無法觸發(fā)
解決方法是直接重寫titleView對應View的intrinsicContentSize方法
- (CGSize)intrinsicContentSize {
return UILayoutFittingExpandedSize;
}
7.在IOS11番甩,原有的NSLocationAlwaysUsageDeion被降級為NSLocationWhenInUseUsageDeion。因此届搁,在原來項目中使用requestAlwaysAuthorization獲取定位權(quán)限缘薛,而未在plist文件中配置NSLocationAlwaysAndWhenInUseUsageDeion窍育,系統(tǒng)框不會彈出。建議新舊key值都在plist里配置掩宜,反正我試下來是沒有問題蔫骂,唯一的區(qū)別是使用requestAlwaysAuthorization獲取權(quán)限 IOS11系統(tǒng)彈框會把幾種權(quán)限級別全部列出,供用戶選擇牺汤,顯然更人性化了哈~~