您的位置:首页 > 移动开发 > IOS开发

IOS7 TableView适配

2015-11-07 10:50 621 查看
ios7下的app都是全屏的,意思就是所有控制器的view默认都是从屏幕的(0,0)开始。

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

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:

  UIViewController添加到uiNavController上时,uiviewcontroller的y值 == 状态栏的的y

  这时候设置

      self.edgesForExtendedLayout = UIRectEdgeNone;

  uiviewcontroller的y值 == 导航栏y + 导航栏height

  /*

    这种情况还可以设置,导航栏的bar的透明度属性translucent为no

      self.navigationController.navigationBar.translucent = NO;

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

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

  */

  例如2:

  UITableViewController添加到UITabBarController上时,UITableViewController的底部一部分cell会被TabBar挡住

  这时候设置

      self.edgesForExtendedLayout = UIRectEdgeNone;

  TabBar的y值 == CGRectGetMaxY(UITableViewController)

二 : 

  self.extendedLayoutIncludesOpaqueBars = YES;

  意思展开包括状态栏

三:

self.automaticallyAdjustsScrollViewInsets = YES;

  当设计到scrollView、tableview时,在设置完数据的时候,内部会改变contentInsets的top值为64

  例如:

    group样式的tableView在有导航栏的控制器下,第0组的头部会多出一部分高度h

    原因是

      ios7下group样式的tabelView的第0组第0个cell,在tableview中的y值为35!!!

      并且在设置完cell数据之后,系统默认会执行

        self.automaticallyAdjustsScrollViewInsets = YES;

        也就是tableview的contentInset.top = 64;

    

    所以 第0组第0行cell的y值 = 64 + 35.

    

    要达到第0组第0行cell的y值 = 导航栏底部 的效果

    就要在cell设置数据之前,

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

    这样在cell在设置完数据后,系统内部改变top值增加64,就恰好达到效果。

    

    若要达到每个group头部等高效果,    

     tableView.sectionHeaderHeight = cellSectionHeight;

     tableView.sectionFooterHeight = 0;

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

原文链接:http://www.cnblogs.com/wangxiaofeinin/p/3532831.html?utm_source=tuicool&utm_medium=referral
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: