需求:取消UITableView的Footer自带的悬停效果,但不是隐藏,还是要在表格最后显示footer。
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.tableView)
{
UITableView *tableview = (UITableView *)scrollView;
CGFloat sectionHeaderHeight = 64;
CGFloat sectionFooterHeight = 44;
CGFloat offsetY = tableview.contentOffset.y;
if (offsetY >= 0 && offsetY <= sectionHeaderHeight)
{
tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);
}else if (offsetY >= sectionHeaderHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight)
{
tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);
}else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height)
{
tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight), 0);
}
}
}
对于继承UITableViewController,如果想更改tableview样式,请重写初始化方法:
- (instancetype)initWithStyle:(UITableViewStyle)style {
return [super initWithStyle: UITableViewStyleGrouped];
}
另外,可以去掉头部间距
// 隐藏UITableViewStyleGrouped上边多余的间隔
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
每个人的情况可能不太一样,笔者这里的验证结果可能只针对特定情况,读者自行根据实际情况参考和判断。也可以在评论区留言写下你工程背景和验证情况。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有