您的位置:首页 > 移动开发 > IOS开发

[10秒学会] - iOS tableView中headView和footView悬停方式

2016-05-12 00:00 375 查看
摘要: [10秒学会] - iOS tableView中headView和footView悬停方式

效果图头部悬停 底部不悬停




一共4种

一: 2个都悬停 UITableViewStylePlain //没什么好疑问的
二:2个都不悬停 UITableViewStyleGrouped //也没啥好疑问的
三:头部不悬停 底部悬停 使用UITableViewStylePlain //网上已经很多这个代码 还是贴一下吧

[code=plain]-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
//    if (scrollView == self.myTableView)
{
//YOUR_HEIGHT 为最高的那个headerView的高度
//        CGFloat sectionHeaderHeight = 20;
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);
}
}
}

四 才是今天我们的重点 头部悬停 底部不悬停

[code=plain]    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -105, 0); //首先改变内边距 -105是底部的距离
CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:5 inSection:2]]; //现在是写死的 你可以根据模型数据 写成变量
CGRect rect = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];//这是是最后cell row的高度
if(rect.origin.y<=-1288){ //-1288  这个位置 是可以根据你的位置调整出来
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}else{
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -105, 0);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: