? ? ?在設(shè)置了NavigationController,在self.view中添加視圖的烁,會發(fā)現(xiàn)默認(rèn)的坐標(biāo)起點是屏幕的左上角褐耳。這是因為在iOS7后,NavigationController有一個新屬性“translucent”默認(rèn)為YES渴庆;(這個屬性就是設(shè)置導(dǎo)航欄是否具有透明度這個功能)铃芦。
取消透明度:
[[UINavigationBar appearance] setTranslucent:NO]; ? ? ? ? //全局去掉透明度
self.navigationController.navigationBar.translucent =NO; ? ?//單獨去掉一個controller的導(dǎo)航欄透明度
(1)當(dāng)translucent = YES,controller中self.view的原點是從導(dǎo)航欄左上角開始計算;
? ? ?在translucent = YES的時候襟雷,Controller中改變self.view計算原點位置:
?self.edgesForExtendedLayout =UIRectEdgeNone;//從navigationBar下面開始計算一直到屏幕tabBar上部
self.edgesForExtendedLayout =UIRectEdgeAll;//從屏幕邊緣計算(默認(rèn))
self.edgesForExtendedLayout =UIRectEdgeTop;//navigationBar下面開始計算一直到屏幕tabBar上部
self.edgesForExtendedLayout =UIRectEdgeBottom;//從navigationBar下面開始計算一直到屏幕底部
(2)當(dāng)translucent = NO刃滓,controller中self.view的原點是從導(dǎo)航欄左下角開始計算;
? ? ? translucent = NO的時候,設(shè)置self.edgesForExtendedLayout 是沒有效果的耸弄。
注:
如果想單獨的將一個controller導(dǎo)航欄的Translucent設(shè)置為YES咧虎;
self.navigationController.navigationBar.translucent =YES;? 然后在viewWillDisappear方法中設(shè)置回NO,這樣就不會影響外面的Controller计呈。