edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性见解

iOS7之后的版本,viewController为全屏布局,坐标系起点为屏幕的左上角,这些属性会对坐标系的起点有影响

edgesForExtendedLayout

edgesForExtendedLayout The extended edges to use for the layout. This
property is applied only to view controllers that are embedded in a
container such as UINavigationController. The window’s root view
controller does not react to this property. The default value of this
property is UIRectEdgeAll.

只给viewController的view加个红色背景色

self.view.backgroundColor = [UIColor redColor];

edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性见解_第1张图片
这个属性是指定屏幕延伸的方向,这个属性默认为UIRectEdgeAll,即向屏幕的四周延伸
现在设置这个属性为UIRectEdgeNone,看看结果
edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性见解_第2张图片

self.edgesForExtendedLayout = UIRectEdgeNone;

extendedLayoutIncludesOpaqueBars

A Boolean value indicating whether or not the extended layout includes
opaque bars. The default value of this property is NO. Note Bars are
translucent by default in iOS 7.0

延伸的布局是否包含一个不透明的bar,在iOS7之后bar默认是半透明的
现在给navigationBar设置一个纯色不透明的背景图片

// 生成纯色图片
CGSize imageSize =CGSizeMake([[UIScreen mainScreen] bounds].size.width, 44);
UIGraphicsBeginImageContextWithOptions(imageSize,0, [UIScreen mainScreen].scale);
[[UIColor blueColor] set];
UIRectFill(CGRectMake(0,0, imageSize.width, imageSize.height));
UIImage *pressedColorImg =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// 设置导航栏背景
[self.navigationController.navigationBar setBackgroundImage:pressedColorImg forBarMetrics:UIBarMetricsDefault];

// 测试view
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 10, 200, 100)];
view.backgroundColor = [UIColor blackColor];
[self.view addSubview:view];

edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性见解_第3张图片

现在设置extendedLayoutIncludesOpaqueBars的属性值为YES

self.extendedLayoutIncludesOpaqueBars = YES;

edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性见解_第4张图片

可以发现现在页面的起始坐标变成了屏幕左上角

automaticallyAdjustsScrollViewInsets

A Boolean value that indicates whether the view controller should
automatically adjust its scroll view insets. The default value of this
property is YES, which lets container view controllers know that they
should adjust the scroll view insets of this view controller’s view to
account for screen areas consumed by a status bar, search bar,
navigation bar, toolbar, or tab bar. Set this property to NO if your
view controller implementation manages its own scroll view inset
adjustments.

这个属性决定视图控制器会不会自动的帮我们处理例如ScrollView以及继承于它的控件。这个属性默认为YES,如果我们希望手动的去控制视图的显示,就设置这个属性为NO
未设置的情况下
edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性见解_第5张图片

设置这个属性为NO

self.automaticallyAdjustsScrollViewInsets = NO;

edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性见解_第6张图片
坐标起点变为了屏幕左上角

你可能感兴趣的:(布局,ios7,坐标系起点,iOS开发)