您的位置:首页 > 产品设计 > UI/UE

让UITableview里自定义分区头部随着滑动而滑动

2016-03-28 10:22 477 查看
-(CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section{

    return self.view.bounds.size.height/3 ;

}

-(UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section{

    UIView *view =
[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,self.view.bounds.size.height/3)];

    view.backgroundColor =
[UIColor purpleColor];

    return view ;

 

}

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

    if (scrollView == self.tableView)
{

        CGFloat height
= self.view.bounds.size.height/3;

        if (scrollView.contentOffset.y <=
height && scrollView.contentOffset.y > 0)
{

            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);

            NSLog(@"1...%f",scrollView.contentOffset.y);

        }

        else if(scrollView.contentOffset.y >=
height){

            scrollView.contentInset = UIEdgeInsetsMake(-height, 0, 0, 0);

            NSLog(@"2...%f",scrollView.contentOffset.y);

        }

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息