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;

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值