美文网首页
导航栏的几个属性(2018-05-10)

导航栏的几个属性(2018-05-10)

作者: 小的小碰撞 | 来源:发表于2018-05-22 16:03 被阅读0次

    首先我们先来看下这几个属性:

    • edgesForExtendedLayout
      self.edgesForExtendedLayout = UIRectEdgeNone;
    • translucent
      self.navigationController.navigationBar.translucent = NO;
    • automaticallyAdjustsScrollViewInsets
      self.automaticallyAdjustsScrollViewInsets = NO;
    • contentInsetAdjustmentBehavior
      self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    • extendedLayoutIncludesOpaqueBars
      self.extendedLayoutIncludesOpaqueBars = YES;

    edgesForExtendedLayout

    • 默认情况下为UIRectEdgeAll意味着全屏布局(带穿透效果)意思是view的边缘允许额外布局的情况
    • 当为 UIRectEdgeNone意味着你告诉view不要讲其扩展到整个屏幕 ,当为此时屏幕原点{0,0}就是从导航栏下开始的。==> {0,0} == {0,64}

    translucent

    • 默认情况:self.navigationController.navigationBar.translucent = YES;,VC的坐标原点就是屏幕的左上角开始,当VC添加的第一个子控件不是UIScrollView或者其子类时,automaticallyAdjustsScrollViewInsets 属性将不起作用。当frame(0,0,)时,将会在被导航栏遮盖住,而如果时(0,64)就刚刚好。 相反,如果VC的第一个子控件是UIScrollView或者其子类时,默认为YES,设置为YES时,将发生导航栏(64)高度的偏移量
      contentOffset: {0, -64},adjustedContentInset: {64, 0, 0, 0}> 增加64的内边距

    • self.navigationController.navigationBar.translucent = NO,时,VC的坐标原点{0,0}是从导航栏下面开始的

    extendedLayoutIncludesOpaqueBars

    • 意思是额外布局是否包括不透明的Bar,默认是NO,该属性只对不透明的Bar控件有效。

    automaticallyAdjustsScrollViewInsets

    • 意思是是否由系统自动调整滚动试图的内边距,默认为YES,意味着系统将会根据导航条和TabBar的情况自动增加上下内边距以防止滚动地图的内容被Bar挡住。

    contentInsetAdjustmentBehavior

    • UIScrollViewContentInsetAdjustmentAutomatic 和scrollableAxes一样,scrollView会自动计算和适应顶部和底部的内边距并且在scrollView 不可滚动时,也会设置内边距.
    • UIScrollViewContentInsetAdjustmentScrollableAxes 自动计算内边距.
    • UIScrollViewContentInsetAdjustmentNever不计算内边距
    • UIScrollViewContentInsetAdjustmentAlways根据safeAreaInsets 计算内边距
      通常设置
    if (@available(iOS 11.0, *)) {
            self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        } else {
           self.automaticallyAdjustsScrollViewInsets = NO;
    
        }
    

    参考资料

    相关文章

      网友评论

          本文标题:导航栏的几个属性(2018-05-10)

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