1、iOS 11之前的導(dǎo)航欄的高度是64px(狀態(tài)條+導(dǎo)航欄),iOS11之后如果設(shè)置了prefersLargeTitles = YES(默認(rèn)NO)則為96pt。所以一般不用管。
2、在iOS 11上運(yùn)行tableView向下偏移64px或者20px,因?yàn)閕OS 11廢棄了automaticallyAdjustsScrollViewInsets,而是給UIScrollView增加了contentInsetAdjustmentBehavior屬性。避免這個(gè)坑的方法是要判斷
if?(@available(iOS?11.0,?*))?{
_tableView.contentInsetAdjustmentBehavior?=?UIScrollViewContentInsetAdjustmentNever;
}else?{
self.automaticallyAdjustsScrollViewInsets?=?NO;
}
3、tableView的sectionHeader、sectionFooter高度與設(shè)置不符,因?yàn)閠ableView的estimatedRowHeight、estimatedSectionHeaderHeight、 estimatedSectionFooterHeight三個(gè)高度估算屬性由默認(rèn)的0變成了UITableViewAutomaticDimension。最簡(jiǎn)單的方法就是直接設(shè)置為0。
4、iPhone X狀態(tài)條由20px變成了44px,UITabBar由49px變成了83px。設(shè)置布局時(shí)y直接寫成64的就要根據(jù)機(jī)型設(shè)置??梢栽O(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就可以了
這里要注意的是,需要判斷當(dāng)前系統(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顧名思義,固定大小的意思,主要是解決一些模糊約束的問題。更多知識(shí)可以看這篇文章詳解intrinsicContentSize。
不做適配在IOS11會(huì)遇到的問題:
titleView對(duì)應(yīng)的View大小和預(yù)期不一致。
titleView對(duì)應(yīng)的View有點(diǎn)擊事件會(huì)無(wú)法觸發(fā)
解決方法是直接重寫titleView對(duì)應(yīng)View的intrinsicContentSize方法
- (CGSize)intrinsicContentSize {
return UILayoutFittingExpandedSize;
}
7.在IOS11,原有的NSLocationAlwaysUsageDeion被降級(jí)為NSLocationWhenInUseUsageDeion。因此,在原來項(xiàng)目中使用requestAlwaysAuthorization獲取定位權(quán)限,而未在plist文件中配置NSLocationAlwaysAndWhenInUseUsageDeion,系統(tǒng)框不會(huì)彈出。建議新舊key值都在plist里配置,反正我試下來是沒有問題,唯一的區(qū)別是使用requestAlwaysAuthorization獲取權(quán)限 IOS11系統(tǒng)彈框會(huì)把幾種權(quán)限級(jí)別全部列出,供用戶選擇,顯然更人性化了哈~~