? ? ? Xcode9升級很開心涛目,運行項目app崩潰頁面也跟預(yù)想的不太一樣欺矫。要打臉了沈跨。接下來做下iOS11適配了偷厦。給大家總結(jié)一下本人踩的坑分享與大家商叹。
1.? Tableview. CollectionView類似的都是表
? ? ? UIScrollView以及子類frame整體下移問題,原因:在iOS 11中被棄用只泼,取而代之的是UIScrollView的 contentInsetAdjustmentBehavior沈自。導(dǎo)致整個頁面布局錯誤。若項目中未使用automaticallyAdjustsScrollViewInsets屬性辜妓,則無需適配你的頁面也正常(相對而言)解決辦法可以針對iOS 11用新API:
if (@available(iOS 11,*)) {
if ([tableview respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
} 另一方面枯途,iOS11 默認推薦系統(tǒng)自動估算行高方式,想關(guān)閉也行的采用這種方式:
解決方法一 :添加實現(xiàn)View的代理方法籍滴,只有實現(xiàn)下面兩個方法酪夷,方法 (CGFloat)tableView: heightForFooterInSection: 才會生效
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return nil;
}// 解決方法二:直接使用tableView屬性進行設(shè)置,修復(fù)該UI錯亂
self.tableView.sectionHeaderHeight = 0;
self.tableView.sectionFooterHeight = 5;
[_optionTableView setContentInset:UIEdgeInsetsMake(-35, 0, 0, 0)];
// 解決方法三:添加以下代碼關(guān)閉估算行高
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
加一框架? Masonry布局需要做下處理
if ([UIDevice currentDevice].systemVersion.floatValue >= 11.0) {
make.edges.equalTo(self.view.safeAreaInsets);
} else {
make.edges.equalTo(self.view);
}
如果想更深了解參考這個鏈接,騰訊Bugly:https://mp.weixin.qq.com/s/W1_0VrchCO50owhJNmJnuQ
2.狀態(tài)欄在iPhone X上高度改變孽惰。及iPhone X適配
先看一下iPhone屏幕分辨率
啟動頁設(shè)置
規(guī)定的就是規(guī)定的晚岭,沒有為什么。最好的方法統(tǒng)一動態(tài)加載:
狀態(tài)欄(statusbar)
CGRect StatusRect = [[UIApplication sharedApplication] statusBarFrame];
//標(biāo)題欄
CGRect NavRect = self.navigationController.navigationBar.frame;
然后將高度相加勋功,計算頂部高度坦报。不再寫64
官方文檔: https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/
3.定位權(quán)限
IOS11库说,原有的NSLocationAlwaysUsageDeion被降級為NSLocationWhenInUseUsageDeion。因此片择,在原來項目中使用requestAlwaysAuthorization獲取定位權(quán)限潜的,而未在plist文件中配置NSLocationAlwaysAndWhenInUseUsageDeion,系統(tǒng)框不會彈出字管。如:
4.導(dǎo)航上titleView
重寫此方法完成布局啰挪,避免放按鈕點擊區(qū)域改變造成無響應(yīng)事件。
- (CGSize)intrinsicContentSize {
return UILayoutFittingExpandedSize;
}
5. 持續(xù)更新