UITableView/UIScrollView内容视图下移

先来看看,普通控制上添加一个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;

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


文章来自:http://blog.csdn.net/adadadadadadad40/article/details/46275781
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3