Ucself


嗨,我是ucself,一名大前端开发工程师。


总结与创造,学习与创新,搭建自我知识体系。

iOS UIViewController的self.view布局位置问题。

前言

       在平时的开发中,打开布局查看器老是遇见 self.view 有的控制器顶在了 navagationbar 上面,有的控制器顶在了 navagationbar 下面;一直很纠结这个问题,最近专门研究一下,并记录下来。

image.png

这里不做详细介绍了,如果不愿意详细看下面文章就看我总结吧,很详细的介绍在:https://www.jianshu.com/p/6925ce1b9e34

这里做一个总结:

  • 影响到 self.view 是顶入顶部(有 navagationbar)或者底部(有 tabbar)有三个属性可以影响到:
  1. isTranslucent(所属 UINavigationBar),
  2. edgesForExtendedLayout(所属 UIViewController),
  3. extendedLayoutIncludesOpaqueBars(所属 UIViewController)
  • isTranslucent 与 edgesForExtendedLayout 相互影响是否顶入顶部或底部, 举例:

    1. (isTranslucent 为 true 和 edgesForExtendedLayout 为 all )就 self.view 顶入顶部和底部,
    2. (isTranslucent 为 false 和 edgesForExtendedLayout 为 all )就 self.view 不顶入顶部和底部,
    3. (isTranslucent 为 true 和 edgesForExtendedLayout 为.top )就 self.view 顶入顶部和不顶入底部, 其他的属性就自己揣测吧。
  • extendedLayoutIncludesOpaqueBars = true 可忽略 isTranslucent 对导航栏的影响(可以理解为:在其他默认设置情况先设置 extendedLayoutIncludesOpaqueBars = true, self.view 顶入顶部和底部);

上一篇文章

2018年终总结,2019年初计划

下一篇文章

swift 工程 TARGETS与预定义宏