zoukankan      html  css  js  c++  java
  • AJ学IOS 之tableView的下拉放大图片的方法

    AJ分享,必须精品

    一:效果

    tableview下拉的时候上部分图片放大会
    这里写图片描述

    二:代码

    直接上代码,自己研究吧

    
    #import "NYViewController.h"
    
    //图片的高度
    const CGFloat NYTopViewH = 350;
    
    @interface NYViewController ()
    @property (nonatomic, weak) UIImageView *topView;
    @end
    
    @implementation NYViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        // 设置内边距(让cell往下移动一段距离)
        self.tableView.contentInset = UIEdgeInsetsMake(NYTopViewH * 0.5, 0, 0, 0);
    
        UIImageView *topView = [[UIImageView alloc] init];
        topView.image = [UIImage imageNamed:@"biaoqingdi"];
        topView.frame = CGRectMake(0, -NYTopViewH, 320, NYTopViewH);
    
        //设置图片内容模式,让按照原来宽高比缩放
        topView.contentMode = UIViewContentModeScaleAspectFill;
        [self.tableView insertSubview:topView atIndex:0];
        self.topView = topView;
    }
    
    #pragma mark - 数据源方法
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 20;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *ID = @"cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        }
    
        cell.textLabel.text = [NSString stringWithFormat:@"测试数据---%d", indexPath.row];
    
        return cell;
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        // 向下拽了多少距离
        CGFloat down = -(NYTopViewH * 0.5) - scrollView.contentOffset.y;
        if (down < 0) return;
    
        CGRect frame = self.topView.frame;
    
        // 5决定图片变大的速度,值越大,速度越快
        frame.size.height = NYTopViewH + down * 5;
        self.topView.frame = frame;
    }
    
    @end
    
  • 相关阅读:
    作用域 + this指向 的一道没面试题
    找出数组中最大的值
    统计数组中每个值出现的次数, 统计对象中每个字符出现的次数
    uniapp在h5 和 APP 端兼容性 bug 解决方案
    数组去重的常用方法,利用Promise实现函数按序执行
    momentjs实现距离当前时长并且回现中文效果
    SQL server 上机练习题
    JS 9
    JS 8
    JS 7
  • 原文地址:https://www.cnblogs.com/luolianxi/p/4990282.html
Copyright © 2011-2022 走看看