下拉头图放大 iOS

 属性记录头图滑动前的位置

@property (nonatomic,strong)UIView *mHeadView;
@property (nonatomic,assign)CGFloat mHeadViewHeight;
@property (nonatomic,assign)CGRect mHeadViewFrame;
@property (nonatomic,assign)CGPoint mHeadViewCenter;

 

 将头图放到self.view上,列表放到self.view上。

    //头图的高度
    self.mHeadViewHeight = UIScreenWidth*0.9;
    
    [self.view addSubview:weakself.mHeadView];
    [self.view addSubview:weakself.mTableView];
    
    //记录一下滑动前的位置
    self.mHeadViewFrame = self.mHeadView.frame;
    self.mHeadViewCenter = self.mHeadView.center;
    //设置列表上偏移头图的高度
    self.mTableView.contentInset = UIEdgeInsetsMake(self.mHeadViewHeight, 0, 0, 0);
    [self.mTableView setContentOffset:CGPointMake(0, -self.mHeadViewHeight)];

 关键代码,处理滚动逻辑

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if(scrollView == _mTableView){
        CGFloat height = scrollView.contentOffset.y;
        if(height < -self.mHeadViewHeight){
            CGFloat scale = (-height)/self.mHeadViewHeight;
            scale = MAX(scale, 1);
            self.mHeadView.frame = CGRectMake(0, 0, self.mHeadViewFrame.size.width * scale, self.mHeadViewFrame.size.height*scale);
        }else{
            self.mHeadView.frame = self.mHeadViewFrame;
            
        }
        self.mHeadView.center = self.mHeadViewCenter;
        self.mHeadView.top = 0;
    }
}

 

懒加载,头图视图

-(UIView *)mHeadView{
    if(!_mHeadView){
        _mHeadView = [[UIView alloc]init];
        _mHeadView.frame = CGRectMake(0, 0, UIScreenWidth, self.mHeadViewHeight);
        _mHeadView.backgroundColor = [UIColor whiteColor];
    }
    return _mHeadView;
}

 

在北京的灯中,有一盏是我家的。这个梦何时可以实现?哪怕微微亮。北京就像魔鬼训练营,有能力的留,没能力的走……
posted @ 2021-09-08 09:13  黄增松  阅读(11)  评论(0编辑  收藏  举报