iOS 7以后ViewController开始全屏布局
edgesForExtendedLayout,它是一个类型为UIExtendedEdge的属性,指定边缘要延伸的方向,它的默认值很自然地是all,四周边缘均延伸,就是说,如果即使视图中上有navigationBar,下有tabBar,那么视图仍会延伸覆盖到四周的区域。
新建一个空项目, 在
Storyboard中embed一个Navigation Controller:
默认演示.png
默认hierarchy.png
因为默认是
all, 这里在默认关联的ViewController中将edgesForExtendedLayout指定成了.bottom, 相当于取消了顶部
代码:edgesForExtendedLayout = .bottom
取消top.png
取消top hierarchy.png
通过截图来看的确达到了我们的预期效果, 但也因此影响到了
navigationBar, 变成灰色了, 这时我们在通过translucent取消穿透效果:
代码:self.navigationController?.navigationBar.isTranslucent = false
取消translucent.png
取消translucent hierarchy.png

默认演示.png
默认hierarchy.png
取消top.png
取消top hierarchy.png
取消translucent.png
取消translucent hierarchy.png








网友评论