NB的iOS 11發(fā)布了,適配工作又來了??,本文主要記錄APP幾個需要適配的地方。
一:navigation bar
1、導(dǎo)航欄新增了一種大標(biāo)題樣式渔欢,默認(rèn)設(shè)置是不開啟,所以不需要修改瘟忱。
2奥额、titleView
支持autolayout
,這要求titleView
必須是能夠自撐開的或?qū)崿F(xiàn)了- intrinsicContentSize
访诱,簡書的搜索就變成下面這樣了
解決辦法比較簡單垫挨,這個搜索框?qū)?yīng)的view
實現(xiàn)- intrinsicContentSize
方法
- (CGSize)intrinsicContentSize {
return UILayoutFittingExpandedSize;
}
二:安全區(qū)域適配
iOS 11中ViewController
的automaticallyAdjustsScrollViewInsets
屬性被廢棄了,導(dǎo)致了這兩個頁面出現(xiàn)了問題
這個頁面都隱藏了系統(tǒng)導(dǎo)航欄触菜,自定義導(dǎo)航欄九榔。
self.automaticallyAdjustsScrollViewInsets = NO;
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeTop;
automaticallyAdjustsScrollViewInsets
屬性被廢棄了,頂部就多了一定的inset
涡相,關(guān)于安全區(qū)域適配哲泊,簡書上的這篇文章iOS 11 安全區(qū)域適配總結(jié)介紹得非常詳細(xì),請參考這篇文章催蝗。
我們采用了比較簡單的方法
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
三:導(dǎo)航欄返回按鈕
之前的代碼通過下面的方式自定義返回按鈕
UIImage *backButtonImage = [[UIImage imageNamed:@"icon_tabbar_back"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 18, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
forBarMetrics:UIBarMetricsDefault];
iOS 11 中setBackButtonTitlePositionAdjustment:UIOffsetMake
沒法把按鈕移出navigation bar
切威。
解決方法是設(shè)置navigationController
的backIndicatorImage
和backIndicatorTransitionMaskImage
UIImage *backButtonImage = [[UIImage imageNamed:@"icon_tabbar_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationBar.backIndicatorImage = backButtonImage;
self.navigationBar.backIndicatorTransitionMaskImage = backButtonImage;
四:tableview問題
iOS 11中如果不實現(xiàn)
-tableView: viewForFooterInSection:
和-tableView: viewForHeaderInSection:
,那么-tableView: heightForHeaderInSection:
和- tableView: heightForFooterInSection:
不會被調(diào)用丙号。
這是因為estimatedRowHeight
estimatedSectionHeaderHeight
estimatedSectionFooterHeight
三個高度估算屬性由默認(rèn)的0變成了UITableViewAutomaticDimension
先朦,導(dǎo)致高度計算不對,解決方法是實現(xiàn)對應(yīng)方法或吧這三個屬性設(shè)為0犬缨。
下面這個列表顯示不全也是estimatedRowHeight
引起喳魏,取contentSize
出錯。
五:第三方依賴庫問題
1遍尺、ReactiveCocoa Unknown warning group ‘-Wreceiver-is-weak’
,ignored
警告
項目開啟
Treat warning as error
截酷,所有警告都會被當(dāng)成錯誤,因此必須解決掉。RACObserve
宏定義如下:
#define RACObserve(TARGET, KEYPATH) \
({ \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wreceiver-is-weak\"") \
__weak id target_ = (TARGET); \
[target_ rac_valuesForKeyPath:@keypath(TARGET, KEYPATH) observer:self]; \
_Pragma("clang diagnostic pop") \
})
在之前的Xcode中如果消息接受者是一個weak
對象迂苛,clang編譯器會報receiver-is-weak
警告三热,所以加了這段push&pop
,最新的clang已經(jīng)把這個警告給移除三幻,所以沒必要加push&pop
了就漾。
ReactiveCocoa
已經(jīng)不再維護(hù)OC版本,大多數(shù)OC開發(fā)者用的都是2.5這個版本念搬,只能自己fork一份了抑堡,誰知github上的v2.5代碼不包含對應(yīng)的.podspec
文件,只好到CocoaPods/Specs
上將對應(yīng)的json文件翻譯成.podspec
文件朗徊,如果你也有這個需要首妖,可以修改Podfile
如
pod
'ReactiveCocoa'
, :git =>
'https://github.com/zhao0/ReactiveCocoa.git'
, :tag =>
'2.5.2'
六:push上下移動
在iOS11后大家會發(fā)現(xiàn)如果我們push一個帶有uiscrollview
的VC或者就是一個帶有UITableview
的VC
時。在push動畫時爷恳,可能會出現(xiàn)一個從左往右并且從下往上移動的情況有缆。這個是因為iOS11的新特性是把safearea
和contentinset
進(jìn)行疊加導(dǎo)致的。解決的方法就是設(shè)置UIScrollView
的 contentInsetAdjustmentBehavior
的屬性值為UIScrollViewContentInsetAdjustmentNever
温亲。記得這個屬性是iOS11哦棚壁。
七:導(dǎo)航欄高度變化
導(dǎo)航欄在iOS10之前都是默認(rèn)的64p,但是栈虚,到了iOS10就不單單是64p了袖外,可以看一下系統(tǒng)的信息App,在iOS11添加了大標(biāo)題.
在上圖可以知道魂务,在iOS11導(dǎo)航欄多了一個
LargeTitleView
曼验,專門顯示大字標(biāo)題用的,整個導(dǎo)航欄的高度達(dá)到了96p粘姜,比之前的導(dǎo)航欄多了32p蚣驼,不過,大字標(biāo)題默認(rèn)是關(guān)閉的相艇,所以一般情況下颖杏,導(dǎo)航欄的高度還是64p。
八:細(xì)節(jié)適配
1,適配UITableView
if#available(iOS11.0, *) {
self.contentInsetAdjustmentBehavior= .never
self.estimatedRowHeight=0
self.estimatedSectionHeaderHeight=0
self.estimatedSectionFooterHeight=0
}else{
}
2,適配UIScrollView
if#available(iOS11.0, *) {
scrollView?.contentInsetAdjustmentBehavior= .never
}else{
}
3,適配網(wǎng)頁加載不全下面有白邊
if#available(iOS11.0, *) {
webView.scrollView.contentInsetAdjustmentBehavior= .never
}else{
}
4,適配iPhoneX不能鋪滿屏的問題
給Brand Assets添加一張1125*2436大小的圖片
5,xcode9打包注意事項
xcode9新打包要在構(gòu)建版本的時候加入1024*1024 AppSore icon
首先建議觀看今年WWDC的一個視頻 Updating Your App for iOS 11坛芽,視頻講解了iOS 11一些API的變化留储,對理解適配過程有幫助。
部分內(nèi)容摘自簡書作者zhao0
的文章簡書App適配iOS 11,在此感謝;