iOS NavigationBar + 導航欄 tablevie時候的布局情況,之前迷惑了我很久,怎么也沒法理解透明度會影響布局。
接下來看一下以下三種情況的運行結果
1、全部系統默認情況下利用masory 布局 tableView
[tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.equalTo(self.view); make.bottom.equalTo(self.view.mas_bottom); }];
結果底部發現tableView無法拉到底,如下圖
解決方案:只要一句代碼即可
[tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.equalTo(self.view); make.bottom.equalTo(self.view.mas_bottom);//減去底部tabBar高度 }]; self.edgesForExtendedLayout = UIRectEdgeNone;//自動會計算tabBar高度
2、全局設置 translucent 導航欄為setTranslucent = NO時
[[UINavigationBar appearance] setTranslucent:NO];
顯示效果同 1的結果。 解決方案同1
(這里就很費解,按照系統文檔上解釋的話,默認應該是YES才對,可是事實證明系統默認是NO)
3、全局設置 translucent 導航欄為setTranslucent = YES 時
[[UINavigationBar appearance] setTranslucent:YES];
結果發現tableView 高度開始從導航欄左上角開始計算,結果如下:
解決方案同1,也是設置edgesForExtendedLayout 屬性
self.edgesForExtendedLayout = UIRectEdgeNone;
這里也鏈接一篇說的比較好的文章:http://www.jianshu.com/p/b11769831fef