ios tableView sectionHeader 吸頂效果
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {// any offset changes
// change the position of section header when scrolled by changing scroll's contentInset
CGFloat sectionHeaderHeight = 50;
CGFloat ceilPositon = CGRectGetHeight(_headerView.frame)-sectionHeaderHeight;
if (scrollView.contentOffset.y < sectionHeaderHeight){
scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}
// the "scrollView.contentOffset.y" must larger than its position to ceiling
if (scrollView.contentOffset.y>=ceilPositon && scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(sectionHeaderHeight, 0, 0, 0);
}
}
ceilPositon是我需要的section header的吸頂位置伟叛,當(dāng)tableView的偏移量小于sectionHeaderHeight的時候,正常顯示脐嫂;當(dāng)tableView的偏移量大于ceilPositon统刮,也就是我們期望的吸頂位置的時候,我們就把scrollView.contentInset的top置為sectionHeaderHeight的高度账千,于是就實現(xiàn)了我們想要的效果侥蒙,可以隨意更改section header的吸頂位置。同樣匀奏,此方法也可以使plain類型的tableview失去粘性效果鞭衩,只需要改變scrollView.contentInset即可.
————————————————