总是有那么几个产品经理需求奇葩,ios的tableview中headerview会随着滑动悬停在上方,直到新的sectionheaderview出现并替换掉,这是个好的特性··············
写在tableview代理方法中就好
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let sectionHeaderHeight: CGFloat = “sectionheader的高度”
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)
}
}
网友评论