footer黏性:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionFooterHeight = 30;
float bottomH = scrollView.contentSize.height - CGRectGetHeight(scrollView.frame) - scrollView.contentOffset.y;
if (scrollView.contentOffset.y + sectionFooterHeight >= (scrollView.contentSize.height - CGRectGetHeight(scrollView.frame)))
{
scrollView.contentInset = UIEdgeInsetsMake(0, 0, -MAX(bottomH, 0), 0);
NSLog(@"aaaa");
}
else if (scrollView.contentOffset.y >= sectionFooterHeight)
{
scrollView.contentInset = UIEdgeInsetsMake(0, 0, -sectionFooterHeight, 0);
NSLog(@"vvv");
}
}
headerview黏性:
- (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);
}
}
设置table的style为UITableViewStyleGrouped,也能去掉两个的黏性