美文网首页
iOS6、7 版本适配

iOS6、7 版本适配

作者: 祥子_HelloWorld | 来源:发表于2019-08-03 00:54 被阅读0次

首先

//定义宏,判断ios7
#define IOS7 [[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0
 
//添加代码
if (IOS7)
{
    self.edgesForExtendedLayout = UIRectEdgeNone;               //视图控制器,四条边不指定
    self.extendedLayoutIncludesOpaqueBars = NO;                 //不透明的操作栏<br>    self.modalPresentationCapturesStatusBarAppearance = NO;
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
    if (IOS7)
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
//        self.automaticallyAdjustsScrollViewInsets = NO;
//        self.navigationController.navigationBar.translucent = NO;
//        self.tabBarController.tabBar.translucent = NO;
    }
#endif

self.automaticallyAdjustsScrollViewInsets = NO;
看这个UIViewController的这个属性你就明白了,此属性默认为YES,这样UIViewController下如果只有一个UIScollView或者其子类,那么会自动留出空白,让scollview滚动经过各种bar下面时能隐约看到内容。但是每个UIViewController只能有唯一一个UIScollView或者其子类,如果超过一个,需要将此属性设置为NO,自己去控制留白以及坐标问题。

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/zcw-ios/articles/3340197.html
http://www.cnblogs.com/wangxiaofeinin/p/3532831.html?utm_source=tuicool

相关文章

网友评论

      本文标题:iOS6、7 版本适配

      本文链接:https://www.haomeiwen.com/subject/psildctx.html