iOS tableView中headView和footView懸停方式

簡單的記錄下今天遇到的一個比較感興趣的問題,總共有四種

一: 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);

? ? }

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容