edgesForExtendedLayout

Starting in iOS7, the view controllers use full-screen layout by default. At the same time, you have more control over how it lays out its views, and that's done with those properties:

edgesForExtendedLayout

Basically, with this property you set which sides of your view can be extended to cover the whole screen. Imagine that you push a UIViewController into a UINavigationController, when the view of that view controller is laid out, it will start where the navigation bar ends, but this property will set which sides of the view (top, left, bottom, right) can be extended to fill the whole screen.

ViewController *vc = [[ViewController alloc] init];
vc.view.background = [UIColor purpleColor];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

Here you are not setting the value of edgesForExtendedLayout, therefore the default value is taken (UIRectEdgeAll), so the view extends its layout to fill the whole screen.

屏幕快照 2017-03-05 下午11.17.46.png

As you can see, the red background extends behind the navigation bar and the status bar.

Now, you are going to set that value to UIRectEdgeNone, so you are telling the view controller to not extend the view to cover the screen:

屏幕快照 2017-03-05 下午11.20.31.png
总结来说:

edgesForExtendedLayout
第一:
决定控制器的View的位置是在navigationBar的下边开始还是从手机屏幕( the screen)开始。
第二:
如何理解:
ViewController *vc = [[ViewController alloc] init];
vc.view.background = [UIColor purpleColor];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

这个时候,可以看到,存在navigationBar,并且navigationBar是透明的,默认值为UIRectEdgeAll。

这个时候,,需要注意的是ViewController的View的位置,设置为UIRectEdgeAll,ViewController的View铺满了整个屏幕,而设置为UIRectEdgeNone,需要注意的ViewController的View并未铺满屏幕,起始位置是从navigationBar的下方开始。

参考:
http://stackoverflow.com/questions/18798792/explaining-difference-between-automaticallyadjustsscrollviewinsets-extendedlayo

http://www.cnblogs.com/wangxiaofeinin/p/3532831.html?utm_source=tuicool&utm_medium=referral

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容