zoukankan      html  css  js  c++  java
  • 下拉头图放大 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;
    }
    在北京的灯中,有一盏是我家的。这个梦何时可以实现?哪怕微微亮。北京就像魔鬼训练营,有能力的留,没能力的走……
  • 相关阅读:
    移动端web
    递归求和
    json的基础了解
    冒泡排序的编程方法
    js面向对象
    1002,javascript的原型属性
    1001,instanceof关键字以及typeof关键字
    19,简述一下src与href的区别(不懂)
    531,<form>action属性
    530,css outline属性
  • 原文地址:https://www.cnblogs.com/huangzs/p/15239573.html
Copyright © 2011-2022 走看看