zoukankan      html  css  js  c++  java
  • 图片下拉放大

    //  ViewController.h
    
    #import <UIKit/UIKit.h>
    
    @interface ViewController : UITableViewController
    
    
    @end
    
    //  ViewController.m
    
    #import "ViewController.h"
    
    const CGFloat HMTopViewH = 350; // 设置图片高度
    
    @interface ViewController ()
    
    @property (nonatomic, weak) UIImageView *topView;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    //  1.  self.tableView.tableHeaderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"biaoqingdi"]];
        // 设置内边距(cell往下移动一段距离)
        self.tableView.contentInset = UIEdgeInsetsMake(HMTopViewH * 0.5, 0, 0, 0);
        
        UIImageView *topView = [[UIImageView alloc] init];
        topView.image = [UIImage imageNamed:@"biaoqingdi"];
        topView.frame = CGRectMake(0, -HMTopViewH, 320, HMTopViewH);
        topView.contentMode = UIViewContentModeScaleAspectFill; // 关键代码
    //    在指定的index处插入视图[superView insertSubview:grayView atIndex:0];
        [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 == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
        }
        
        cell.textLabel.text = [NSString stringWithFormat:@"测试数据--%d", indexPath.row];
        
        return cell;
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        // 向下拽了多少距离
        CGFloat down = -(HMTopViewH * 0.5) - scrollView.contentOffset.y;
        if (down < 0) {
            return;
        }
    
        CGRect frame = self.topView.frame;
        // 5决定图片变大的速度,值越大,速度越快
        frame.size.height = HMTopViewH + down * 5; // 关键代码
        self.topView.frame = frame;
    
    }
    
    @end
  • 相关阅读:
    Springboot使用ehcache缓存
    Tomcat启用HTTPS协议配置过程
    细说document.ready和window.onload
    科技创新
    SpringBoot的ApplicationRunner
    禁用Chrome的“请停用以开发者模式运行的扩展程序”提示
    论文排版问题
    mathType换行等号对齐
    内部类调用外部类的成员,同名时怎么调用?
    Tomcat的manager app管理web项目
  • 原文地址:https://www.cnblogs.com/521it/p/5058478.html
Copyright © 2011-2022 走看看