关于UITableView Grouped 头部和尾部的空白留于

由于UITableView的Plain模式时,头部会悬停在界面上,当你需要headerView跟随着UITableView一起移动时,最好还是使用Grouped。虽然有使用UIScroViewDelegate的方法实现Plain模式下不悬停,

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat sectionHeaderHeight = 40;
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
}

但是,是设置contentInset毕竟还是有缺陷,而且没法消除尾部的悬停。所以根据设计的需求,还是使用了Grouped模式。

使用Grouped模式时,出现的问题,section与section之间默认就有空白,直接调用UITableView的dataSource方法,headerForHeight和footerForHeight,return 0是没有用的,上网找了一下,需要设置 

        myTableView.sectionHeaderHeight = 0.0

        myTableView.sectionFooterHeight = 0.0

先消除section于section之间的空白,再调用 headerForHeight和footerForHeight去返回需要自己定义的headerView和footerView。

最后还发现尾部只用有一段留白,网上各种说

        self.automaticallyAdjustsScrollViewInsets = false

        self.edgesForExtendedLayout = .None

 ,但是基本上没什么卵用,最后用这一句消除了尾部的空白:

        tableView.tableFooterView = UIView(frame: CGRectMake(0,0,self.view.width(),0.001))

或者,在footerForHeight返回return 0.001,返回0是没用的,只有return 0.001

 

以上测试为XCODE 7.1 , IOS 8.0以上

 

转载于:https://www.cnblogs.com/swiftpang/p/4997727.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值