首页 > Windows开发 > 详细

UIViewController 的 edgesForExtendedLayout、automaticallyAdjustsScrollViewInsets属性

时间:2016-02-17 12:32:38      阅读:306      评论:0      收藏:0      [点我收藏+]

1.有时你命名设置了某控件的y坐标为0,确总是被导航栏遮挡住,如下:

    UILabel *label = [[UILabel alloc] init];
    label.text = @"请看Y坐标";
    label.frame = CGRectMake(10, 0, 300, 88);
    label.backgroundColor = [UIColor redColor];
    [self.view addSubview:label];

代码效果如下:

技术分享

 

原因分析

在IOS7以后 ViewController 开始使用全屏布局的,而且是默认的行为通常涉及到布局, 就离不开这个属性 edgesForExtendedLayout,它是一个类型为UIExtendedEdge的属性,指定边缘要延伸的方向,它的默认值很自然地是UIRectEdgeAll,四周边缘均延伸,就是说,如果即使视图中上有navigationBar,下有tabBar,那么视图仍会延伸覆盖到四周的区域。

解决方法:
①:self.edgesForExtendedLayout = UIRectEdgeNone;
②:self.navigationController.navigationBar.translucent = NO; (在iOS 6之前(包括iOS 6)translucent默认为NO,从iOS 7开始就默认为YES。)
 
2. 使用UIScrollView也会遇到此种问题:
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREENW, 100)];
    scrollView.contentSize = CGSizeMake(SCREENW * 2, 100);
    scrollView.backgroundColor = [UIColor redColor];
    [self.view addSubview:scrollView];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = @"请看Y坐标";
    label.frame = CGRectMake(10, 0, 300, 88);
    label.backgroundColor = [UIColor redColor];
    [scrollView addSubview:label];
 
代码效果如下:
技术分享
 
 
这种情况也是edgesForExtendedLayout属性造成的。
同样,也需要设置self.edgesForExtendedLayout = UIRectEdgeNone;即可解决问题。
 
 

 

UIViewController 的 edgesForExtendedLayout、automaticallyAdjustsScrollViewInsets属性

原文:http://www.cnblogs.com/xiu619544553/p/5194587.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!