zoukankan      html  css  js  c++  java
  • 新浪微博客户端(64)-下拉放大

    ViewController.m

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property (nonatomic,weak) UIImageView *imageView;
    
    @end
    
    static CGFloat _imageViewWH;
    
    
    @implementation ViewController
    
    
    
    - (void)viewDidLoad {
        [super viewDidLoad];
       
        _imageViewWH = self.tableView.frame.size.width;
        
        
        self.tableView.contentInset = UIEdgeInsetsMake(_imageViewWH * 0.5, 0, 0, 0);
        
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"biaoqingdi"];
        imageView.frame = CGRectMake(0, -(_imageViewWH), _imageViewWH, _imageViewWH);
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        
        [self.tableView insertSubview:imageView atIndex:0];
        self.imageView = imageView;
        
    }
    
    
    
    #pragma mark - TableView 代理方法
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
        return 20;
    
    }
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *ID = @"pull";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        }
        
        cell.textLabel.text = [NSString stringWithFormat:@"第%ld行",indexPath.row];
        return cell;
    
    }
    
    
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    
    
        // 计算当前移动的距离
        // 移动距离 = tableView初始移动距离 - scrollView移动时Y轴方向上的移动距离
        CGFloat moveDistance = -(_imageViewWH * 0.5) - scrollView.contentOffset.y;
        if (moveDistance < 0) return;
        CGRect imageViewF = self.imageView.frame;
        imageViewF.size.height = _imageViewWH + moveDistance * 1.5; // 乘以0.5可加快图片变形速度
        self.imageView.frame = imageViewF;
        
        NSLog(@"当前移动的距离为:%f",moveDistance);
        
    }
    
    
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end

    最终效果:

      

  • 相关阅读:
    SpringMVC Hello World
    SQL Server存储过程同时返回分页结果集和总数
    C#微信公众号开发--网页授权(oauth2.0)获取用户基本信息二
    C#微信公众号开发--网页授权(oauth2.0)获取用户基本信息一
    C#微信公众号开发--微信事件交互
    C# 微信公众号开发--准备工作
    windows环境redis主从安装部署
    javascript设计模式:策略模式
    Unity3d 屏幕截图。并保存。iOS
    注册消息来判断屏幕是否旋转
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6204276.html
Copyright © 2011-2022 走看看