IOS7 导航栏适配

ios7下的app都是全屏的,意思就是所有控制器的view默认都是从屏幕的(0,0)开始。

这时候用到导航栏时,往往会出现view被导航栏挡住情况。

最明显的是用到tableView时,第一行的数据会被导航栏遮盖。

个人总结两种处理办法:

NO.1: 

1 self.navigationController.navigationBar.translucent = NO;

  在控制器下设置导航控制器的导航栏的translucent(半透明)属性为NO,

  translucent属性在ios6之前默认为no,

  而在ios7下的导航栏默认却是半透明的,为yes,所以该属性不会占据空间。

  前提是你不需要导航栏半透明效果。

NO.2:

  ios7,为了达到全屏效果的app,官方增加了几个属性:

1 @property(nonatomic,assign) UIRectEdge edgesForExtendedLayout NS_AVAILABLE_IOS(7_0); // Defaults to UIRectEdgeAll
2  @property(nonatomic,assign) BOOL extendedLayoutIncludesOpaqueBars NS_AVAILABLE_IOS(7_0); // Defaults to NO, but bars are translucent by default on 7_0.  
3  @property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets NS_AVAILABLE_IOS(7_0); // Defaults to YES
      属性edgesForExtendedLayout,意思大概是边缘向四周展开

  edgesForExtendedLayout 值是结构体。默认值是 UIRectEdgeAll,也就是上下左右填充满整个屏幕。

   // 1. UIRectEdgeNone不要往四周边缘展开(按照非iOS7的传统来展示)

1  self.edgesForExtendedLayout = UIRectEdgeNone;

        设置完这一句,压入桟的控制器frame的y值就是从导航条下面开始。

           // 2. NO代表展开的时候不要包含那个导航条

1 //  self.extendedLayoutIncludesOpaqueBars = NO;

       // 3. 若用到tableview

1 self.automaticallyAdjustsScrollViewInsets = YES;

    默认yes,实际内部改变了了scrollViewcontentInsets(比如group样式的tableViewinsets.top=64

    所以要取消自适应,改变contentInsets的top值

1 tableView.contentInset = UIEdgeInsetsMake( x -35,  0,  0,  0);

      // group状态下,sectionFooterHeightsectionHeaderHeight默认是有值的,取消 

1  tableView.sectionFooterHeight = 0;
2 
3  tableView.sectionHeaderHeight = x;

 

 

    

IOS7 导航栏适配

上一篇:PyAV学习笔记(一):PyAV简介、安装及其基础操作


下一篇:爨体书法;扇面