iOS tableView section 和cell 一同滚动的方法

来源:互联网 发布:爱奇艺视频for mac版 编辑:程序博客网 时间:2024/04/27 14:47

1、在ViewDidLoad中添加:

 self.edgesForExtendedLayout = UIRectEdgeNone;

目的是为了来回滚动的时候,不让tableView 顶端在navigationController中。
2、实现scrollView的一个委托:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{    if (scrollView == self.tableView)    {        //sectionHeaderHeight 是section的高度。        CGFloat sectionHeaderHeight = 30;        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);        }    }}
0 0
原创粉丝点击