IOS開發之Bug--iOS7View被導航欄遮擋問題的解決

 

在實際開發中,遇到在UITextView的frame等於當前控制器的View的frame的狀況下,而後運行的時候,發現控制器的Frame的高度y值會從導航條的位置64變化到0。app

致使UITextView的frame也跟着一塊兒移動。ide

這個問題本質其實就是iOS7View被導航欄遮擋問題,因而通過百度搜索到答案。特此下面 複製拷貝 作個簡單的筆記:this

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( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
}

spa

相關文章
相關標籤/搜索