簡單的記錄下今天遇到的一個比較感興趣的問題,總共有四種
一: 2個都懸停?UITableViewStylePlain ?//沒什么好疑問的
二:2個都不懸停?UITableViewStyleGrouped //也沒啥好疑問的
三:頭部不懸停 底部懸停?使用UITableViewStylePlain(網上很多都是這樣的)
-(void)scrollViewDidScroll:(UIScrollView *)scrollView { // if (scrollView == self.myTableView) {
? ? ? ? //YOUR_HEIGHT 為最高的那個headerView的高度? //? ? ? ? CGFloat sectionHeaderHeight = 20;? ? ? ? ? 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);?
? ? ? ? }?
? ? }?
}
四:頭部懸停 底部不懸停
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -105, 0); //首先改變內邊距 -105是底部的距離?
?CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:5 inSection:2]]; //現在是寫死的 你可以根據模型數據 寫成變量 ? ?
CGRect rect = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];//這是是最后cell row的高度
?if(rect.origin.y<=-1288){ //-1288 這個位置 是可以根據你的位置調整出來 self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
? ? }else{
? ? ? ? self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -105, 0);
? ? }