zoukankan      html  css  js  c++  java
  • iOS实现下拉放大的功能

    #import "HMViewController.h"
    
    const CGFloat ICITopViewH = 350;
    
    @interface HMViewController ()
    @property (nonatomic, weak) UIImageView *topView;
    @end
    
    @implementation HMViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        // 设置内边距(让cell往下移动一段距离)
        self.tableView.contentInset = UIEdgeInsetsMake(ICITopViewH * 0.5, 0, 0, 0);
        
        UIImageView *topView = [[UIImageView alloc] init];
        topView.image = [UIImage imageNamed:@"biaoqingdi"];
        topView.frame = CGRectMake(0, -ICITopViewH, 320, ICITopViewH);
        //设置UUIImageView的内容显示模式。来实现下拉放大的关键
        topView.contentMode = UIViewContentModeScaleAspectFill;
        //插入到tableView的第一个子控件,使用addSubView的话,下拉会把底部的Cell遮挡。
        [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:@"测试数据---%ld", (long)indexPath.row];
        
        return cell;
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        // 向下拽了多少距离
        CGFloat down = -(ICITopViewH * 0.5) - scrollView.contentOffset.y;
        if (down < 0) return;
        
        CGRect frame = self.topView.frame;
        // 5决定图片变大的速度,值越大,速度越快
        frame.size.height = ICITopViewH + down * 5;
        self.topView.frame = frame;
    }
    
    @end
  • 相关阅读:
    Shell编程------函数应用
    Shell编程------循环语句
    Shell编程------判断语句
    Shell编程------变量、赋值和运算
    Action实现prepareable接口后定义前置方法
    动态代理模式
    hibernate持久化对象,
    view视图总结
    servlet和Struts2的线程安全性对比
    Action获取请求参数的3中方式
  • 原文地址:https://www.cnblogs.com/alwaysyouare/p/4976069.html
Copyright © 2011-2022 走看看