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

    最终效果:

      

  • 相关阅读:
    fiddler查看IP地址和请求响应时间
    web安全测试排查
    搞站思路 <陆续完善中>
    sys模块进度条玩法笔记
    Webbench、ab命令:做压力测试的工具和性能的监控工具
    xlwings excel(三)
    xlwings excel(二)
    xlwings excel(一)
    xlwings API Documentation
    Python+Excel 操作对比
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6204276.html
Copyright © 2011-2022 走看看