码迷,mamicode.com
首页 > 其他好文 > 详细

UITableView/UIScrollView内容视图下移

时间:2015-05-30 18:17:48      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:uitableview   uiscorllview   

先来看看,普通控制上添加一个UITableView的情况:(设置tableView的背景颜色为蓝色)

技术分享

再来看看实现的代码:

UITableView *tableView = [[UITableView allocinitWithFrame:CGRectMake(00self.view.bounds.size.width,self.view.bounds.size.height)];

    [self.view addSubview:tableView];

    self.tableView = tableView;

    

    self.tableView.backgroundColor = [UIColor blueColor];

    self.tableView.delegate = self;

     self.tableView.dataSource = self;

此时,设置的frame的y明明是0,但是,实际看到的tableViewframe确实是在0位置上(有背景蓝色),但是,它的contentInset的top方向上为64。内容视图向下移动了64,这是为什么呢?

经过百度和google之后,了解到,从ios7以后,控制器有了一个新的属性,automaticallyAdjustsScrollViewInsets, 默认是YES,如果视图里面存在唯一一个UIScorllView或其子类view,那么,它会自动设置相应的内边距,这样可以让scorll占据整个视图,又不会让导航栏遮盖。

如果,我们手动将automaticallyAdjustsScrollViewInsets设置为NO, 这时候看到的情况是:


技术分享

此时代码:

self.automaticallyAdjustsScrollViewInsets = NO;

    

UITableView *tableView = [[UITableView allocinitWithFrame:CGRectMake(00self.view.bounds.size.width,self.view.bounds.size.height)];

    [self.view addSubview:tableView];

    self.tableView = tableView;

    

    self.tableView.backgroundColor = [UIColor blueColor];

    self.tableView.delegate = self;

    self.tableView.dataSource = self;

现在,它不会自动自动调整内边距了。


UITableView/UIScrollView内容视图下移

标签:uitableview   uiscorllview   

原文地址:http://blog.csdn.net/adadadadadadad40/article/details/46275781

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!