第一種方法:在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