第一种方法:在func scrollViewDidScroll(_ scrollView: UIScrollView)方法中写
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == self.tableView{
if scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0{
scrollView.contentInset = UIEdgeInsets(top: -scrollView.contentOffset.y, left: 0, bottom: 0, right: 0)
}else if scrollView.contentOffset.y >= sectionHeaderHeight {
scrollView.contentInset = UIEdgeInsets(top: -sectionHeaderHeight, left: 0, bottom: 0, right: 0)
}
}
}
第二种方法:将tableview的plain改为group