iOS开发笔记--去掉tableview中section的headerview粘性

来源:互联网 发布:桌面文件夹归类软件 编辑:程序博客网 时间:2024/05/10 16:46

ios的tableview中headerview会随着滑动黏在上方,直到新的sectionheaderview出现并替换掉,这是个好的特性,但是在为了实现PM某些需求的时候,又不是很符合心意,在网上查了下,找到了其解决方法:

    // 去掉UItableview headerview黏性(sticky)    - (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);        }    }

利用控制scrollView的滑动来控制headView显示与否。

转自:http://fisher-me.net/?p=495

1 0
原创粉丝点击