ios拓展1-导航栏偏移

作者: Abler | 来源:发表于2016-07-09 20:05 被阅读651次

    在ios开发中,导航栏一般是必不可少的。比如:UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[YYViewController new]];
    但是如果 向控制器 添加一些小的控件,可能会被导航栏遮盖,这个时候我们可以将一下代码,放到 YYViewController 控制器中。

    // 禁用自动偏移oc
        self.modalPresentationCapturesStatusBarAppearance = NO;
        self.edgesForExtendedLayout = UIRectEdgeNone;//主要是这句话
        self.extendedLayoutIncludesOpaqueBars = NO;
    
    swift下代码
            self.edgesForExtendedLayout = UIRectEdge.None
            self.modalPresentationCapturesStatusBarAppearance = false
            self.extendedLayoutIncludesOpaqueBars = false
    

    效果如下 这样 YYViewController 会以导航栏左下角为 起点。

    Snip20160709_6.png
    tips: 如果为tableView时,参数注意
    当 automaticallyAdjustsScrollViewInsets 为 NO 时,tableview 是从屏幕的最上边开始,也就是被 导航栏 & 状态栏覆盖
    当 automaticallyAdjustsScrollViewInsets 为 YES 时,也是默认行为,表现就比较正常了,
    和edgesForExtendedLayout = UIRectEdgeNone 有啥区别? 不注意可能很难觉察, automaticallyAdjustsScrollViewInsets 为YES 时,
    tableView 上下滑动时,是可以穿过导航栏&状态栏的,在他们下面有淡淡的浅浅红色
    
    tips2:
    extendedLayoutIncludesOpaqueBars 
    首先看下官方解释,默认 NO, 但是Bar 的默认属性是 透明的。。。也就是说只有在不透明下才有用
    但是,测试结果很软肋,基本区别不大。。。但是对于解决一些Bug 是还是起作用的,比如说SearchBar的
    跳动问题
    
    tips3:
    //导航条下面是一个UIScrollView,系统会自动的给一个偏移,偏移的值是导航条的高度
        self.automaticallyAdjustsScrollViewInsets= NO;
    

    相关文章

      网友评论

        本文标题:ios拓展1-导航栏偏移

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