- 昨天下午被朋友问了问题,她需要去除TableView的尾视图粘性,结果不会了,网上有去除头视图粘性的方法,去除个尾视图粘性可以根据那个写出来,好吧,写出代码来记录下我们的这菜鸟一刻
- (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);
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// 去除尾视图粘性的方法
CGFloat sectionFooterHeight = 40;
CGFloat size_height = scrollView.contentSize.height;
CGFloat contentOffset_y = scrollView.contentOffset.y;
CGFloat result = size_height - contentOffset_y - [UIScreen mainScreen].bounds.size.height;
if (result > sectionFooterHeight) {
scrollView.contentInset = UIEdgeInsetsMake(64, 0, -sectionFooterHeight, 0);
}else{
if (result>0) {
scrollView.contentInset = UIEdgeInsetsMake(64, 0, -result, 0);
}else{
scrollView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
}
}
}
- 两个方法不能同时写一块,以为两个方法都是通过操作偏移量来实现的,写在一起的话,前一个方法会被后一个方法覆盖