IOS開發---菜鳥學習之路--(二十四)-iOS7View被導航欄遮擋問題的解決


(此文為復制帖,原文地址為:http://blog.sina.com.cn/s/blog_a8192bdd0101af40.html)

self.navigationController.navigationBar.translucent = NO;

如果在iPad上用了split view,並且設置了UINavigationBar的background image,現象為狀態欄一直是一片漆黑

UINavigationController will alter the height of its UINavigationBar to either 44 points or 64 points, depending on a rather strange and undocumented set of constraints. If the UINavigationController detects that the top of its view’s frame is visually contiguous with its UIWindow’s top, then it draws its navigation bar with a height of 64 points. If its view’s top is not contiguous with the UIWindow’s top (even if off by only one point), then it draws its navigation bar in the “traditional” way with a height of 44 points.  This logic is performed by UINavigationController even if it is several children down inside the view controller hierarchy of your application. There is no way to prevent this behavior.



意思就是UINavigationBar的高度會自行調整為44或者64,沒有確定的預測方法。而之前作為UINavigationBar背景的圖片是44高度的。最后換了張64高度,上面留了20px透明的圖片搞定

 
網友還有一種解決辦法
IOS7的視圖有個邊緣延伸的屬性: edgesForExtendedLayout , 
其默認值是UIExtendedEdgeAll。 
只要將其改成UIExtendedEdgeNone即可,要注意的是在IOS7以下版本會出現bug。 
所以在UIViewController 的viewDidLoad里加上下面代碼就完美解決了這個問題 
 
if( ([[[UIDevicecurrentDevice] systemVersion] doubleValue]>=7.0)) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM