美文网首页
tableView区头区尾跟随试图滑动

tableView区头区尾跟随试图滑动

作者: 流老湿 | 来源:发表于2017-10-19 11:00 被阅读15次

只是区头跟随滑动

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGFloat sectionHeaderHeight = kHeadSectionHeight;

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

}

}

区头区尾都跟随滑动

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

if (scrollView == self.tableView) {

CGFloat sectionHeaderHeight = 35;

CGFloat sectionFooterHeight = 25;

CGFloat offsetY = _tableView.contentOffset.y;

if (offsetY >= 0 && offsetY <= sectionHeaderHeight)

{

_tableView.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);

}else if (offsetY >= sectionHeaderHeight && offsetY <= _tableView.contentSize.height - _tableView.frame.size.height - sectionFooterHeight)

{

_tableView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);

}else if (offsetY >= _tableView.contentSize.height - _tableView.frame.size.height - sectionFooterHeight && offsetY <= _tableView.contentSize.height - _tableView.frame.size.height)

{

_tableView.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(_tableView.contentSize.height - _tableView.frame.size.height - sectionFooterHeight), 0);

}

}

}

相关文章

网友评论

      本文标题:tableView区头区尾跟随试图滑动

      本文链接:https://www.haomeiwen.com/subject/ktkuuxtx.html