1. 程式人生 > >屏幕適配1(edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、translucent、automaticallyAdjustsScrollViewInsets)

屏幕適配1(edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、translucent、automaticallyAdjustsScrollViewInsets)

mat 默認 PE ins 底部 int sop win 蘋果

  從iOS7開始,蘋果開始提倡全屏布局,即默認情況下控制器的根View的大小等於屏幕的大小,即使存在navigationBar+tabBar,View的大小不變等於屏幕的大小,這樣導致的結果就是navigationBar和tabBar會將View的頂部和底部的區域覆蓋掉。如下圖結果

技術分享圖片當前根view頂部區域被導航欄覆蓋掉了。

  為了避免上出現被覆蓋的情況,需要修改edgesForExtendedLayout屬性。

edgesForExtendedLayout是一個枚舉類型。

typedef enum : NSUInteger {
   UIRectEdgeNone   = 0,
   UIRectEdgeTop    
= 1 << 0, UIRectEdgeLeft = 1 << 1, UIRectEdgeBottom = 1 << 2, UIRectEdgeRight = 1 << 3, UIRectEdgeAll = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight } UIRectEdge; self.view.edgesForExtendedLayout = UIRectEdgeTop; //表示view向上延伸到屏幕上邊框。 self.view.edgesForExtendedLayout = UIRectEdgeAll; //
表示view向四周延伸到屏幕的各個邊框。 self.view.edgesForExtendedLayout = UIRectEdgeNone; //表示view不向四周延伸,保證不會被navigationbar和tabbar覆蓋掉。

屏幕適配1(edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、translucent、automaticallyAdjustsScrollViewInsets)