UITableView的section header view 不懸停的方法
把 UITableView 的 style 屬性設(shè)置為 Plain 烧给,這個tableview的section header在滾動時會默認懸停在界面頂端慨默。
如果想取消懸停效果,可以采用如下2種方法
1. 修改 UITableView 的 style 屬性設(shè)置為 Grouped. 這時所有的section header都會隨著scrollview滾動了刃麸。不過 grouped 和 plain 的樣式有輕微區(qū)別,切換樣式后也許需要重新調(diào)整UI
2. 如果需要使用 Grouped 這種樣式, 也可以通過重載 scrollView 的 delegate 來達到目的:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 40;
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);
}
}
文/大雨不晴(簡書作者)
原文鏈接:http://www.reibang.com/p/2bb137b15435
著作權(quán)歸作者所有藕漱,轉(zhuǎn)載請聯(lián)系作者獲得授權(quán)闲坎,并標注“簡書作者”。