導航欄的差異
一.導航欄高度變化
- 導航欄在ISO 10 之前都是默認的64,但是在ios 10 之后都變了,在ios 11 添加了大標題,如系統(tǒng)設(shè)置頁面:
- ios11 新增
LargeTitleView
專門用于顯示大標題,不過默認是不顯示的.
設(shè)置這個參數(shù)為yes 顯示導航欄 大標題
self.navigationController.navigationBar.prefersLargeTitles = YES;
- 在 ios11 中iPhone X 和非iphonex 手機的導航欄還是有差異的.
非iPhone X ios11 導航欄結(jié)構(gòu):
20(狀態(tài)欄) + 44(titleView) + 52(largeTitleView-- 這個是新增的)= 116
iPhone X ios11 導航欄結(jié)構(gòu):
44(狀態(tài)欄) + 44(titleView) + 52(largeTitleView-- 這個是新增的)= 140
iphonex 小標題
statusBarFrame {{0, 0}, {375, 44}} 高度多22
navigationBarFrame: {{0, 44}, {375, 44}} y 下降22 高 不變
selfViewFrame: {{0, 0}, {375, 812}}
mainScreen: {{0, 0}, {375, 812}}
selfTabBarControllerTabBarFrame {{0, 729}, {375, 83}}
iphonex 大標題
statusBarFrame {{0, 0}, {375, 20}}
navigationBarFrame: {{0, 20}, {375, 96}}
selfViewFrame: {{0, 0}, {375, 667}}
mainScreen: {{0, 0}, {375, 667}}
selfTabBarControllerTabBarFrame {{0, 618}, {375, 49}}
iphone 8 小標題
statusBarFrame {{0, 0}, {414, 20}}
navigationBarFrame: {{0, 20}, {414, 44}}
selfViewFrame: {{0, 0}, {414, 736}}
mainScreen: {{0, 0}, {414, 736}}
selfTabBarControllerTabBarFrame {{0, 687}, {414, 49}}
二.導航欄圖層變化
ios11之前導航欄的title 是添加在UINavigationItemView上面,而navigationBarButton是直接添加在navigationBar 上面的,如果設(shè)置了titleView,則titleView也只直接添加在navigationBar 上面的.
在ios11 之后,蘋果添加了新的類來管理.navigationBar 會添加在UIButtonBarStackView 上面的,而UIButtonBarStackView 則添加在UINavigationBarContentView上面,如果沒有給titleView賦值,則titleView會直接添加在UINavigationBarContentView 上面,如果賦值了titleView 則會新生成UITAMICAdatptorView, 把titleViewtianjai 在這個類上面,這個類會添加在UInavigationBarContentView 上面.
三.導航欄的邊距變化
在ios11 對導航欄里面的item的邊距也做了調(diào)整:
(1) 如果只是設(shè)置了titleView,沒有設(shè)置barbutton,把titleView的寬度設(shè)置為屏幕的寬度,則titleView 距離屏幕邊距的: ios11 之前 iPhone 6p 上20 p 在iPhone6p 之前 是 16p,ios 11 之后 ,在iPhone6p上是12p,在iPhone6p 之前是8p.
(2) 如果設(shè)置了Barbutton,沒有設(shè)置titleView,則在ios11 里,barbutton距離邊距是20p 和16 p,在ios 11 之前barbutton 邊距距離屏幕的邊距也是20p 和 16p.
(3) 如果同時設(shè)置了titleView 和 barbutton,則在ios11 之前,titleView 和barbutton 之間的間距是6p,在 ios11 上titleView和barbutton 之間無間距.
四. APP 需要實現(xiàn)導航欄左右按鈕邊距為0
在 ios 11 之前,可以設(shè)置一個width 為 負的navigationBarbutton,將按鈕擠到邊緣,變相實現(xiàn)0邊距的導航欄按鈕,但是,這招在ios11 失效了,原因在于UIButtonBarStackView,這個ios 9 之后出來的,用來相對布局的組件,限制了Veiw 的布局,那么怎么搞呢?
想到的方法有幾個:
- 在viewWillAppear 里面,將UIButtonBarStackView 取出來,直接設(shè)置他的x坐標.
- 設(shè)置titleView ,然后將button 添加在titleView 上面,根據(jù)不同的邊距做便宜.
列表的變化
一. automaticallyAdjustsScrollViewInsets
在ios11 之前,如果想要scrollview 不偏移64 ,則需要設(shè)置
automaticallyAdjustsScrollViewInsets = NO, 但是 這個屬性在ios11 直接被拋棄了
tableView 默認使用self-Sizing
這個配合 estimatedRowHeight, estimatedSectionfooterheight, estimatedSectionHeaderheight 使用,可以預估高度.之前,設(shè)置header或者footer高度為0時,需要設(shè)置需要設(shè)置height = 0.1,才會起作用,如果直接設(shè)置為0 ,則會使用默認的高度.ios11 由于自動使用預估高度,所以,忽略了設(shè)置的高度,使用原來的高度增大了.只要把這個屬性設(shè)置成0 就OK了.
ihonex 底部的tabbar 的高度改變
iPhonex 不僅多了劉海,底部還有一個半角的矩形,使得tabbar多出來了34p 的高度,不過不管導航欄和tabbar 一般的系統(tǒng)都會自動適配 safeArea