• 图片点击放大


    //

    //  ViewController.m

    //  图片点击放大

    //

    //  Created by xueshan on 17/1/19.

    //  Copyright © 2017 xueshan. All rights reserved.

    //

     

    #import "ViewController.h"

    #import <QuartzCore/QuartzCore.h>

     

    //设置放大后图片的宽高,为了省时间,偷了下懒,建议最好结合实际做下运算

    #define BIG_IMG_WIDTH  325

    #define BIG_IMG_HEIGHT 325

     

    @interface ViewController ()

    @property (strong, nonatomic) IBOutlet UIImageView *minImageView;

     

     

    @end

     

    @implementation ViewController{

        UIView *background;

    }

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

        

        //允许用户交互

        _minImageView.userInteractionEnabled = YES;

        //添加点击手势

        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];

        [_minImageView addGestureRecognizer:tapGesture];

    }

    //点击图片后的方法(即图片的放大全屏效果)

    - (void) tapAction{

        //创建一个黑色背景

        //初始化一个用来当做背景的View。我这里为了省时间计算,宽高直接用的5s的尺寸

        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 600)];

        background = bgView;

        [bgView setBackgroundColor:[UIColor blackColor]];

        [self.view addSubview:bgView];

        

        //创建显示图像的视图

        //初始化要显示的图片内容的imageView(这里位置继续偷懒...没有计算)

        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, BIG_IMG_WIDTH, BIG_IMG_HEIGHT)];

        //要显示的图片,即要放大的图片

        [imgView setImage:[UIImage imageNamed:@"企业证书账单"]];

        [bgView addSubview:imgView];

        

        imgView.userInteractionEnabled = YES;

        //添加点击手势(即点击图片后退出全屏)

        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeView)];

        [imgView addGestureRecognizer:tapGesture];

        

        [self shakeToShow:bgView];//放大过程中的动画

    }

    -(void)closeView{

        [background removeFromSuperview];

    }

    //放大过程中出现的缓慢动画

    - (void) shakeToShow:(UIView*)aView{

        CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];

        animation.duration = 0.5;

        NSMutableArray *values = [NSMutableArray array];

        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];

        [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];

        animation.values = values;

        [aView.layer addAnimation:animation forKey:nil];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    @end

  • 相关阅读:
    vue关闭eslint
    ThinkPHP 5 项目执行慢问题排查
    Git 操作教程
    转】解决存储过程执行快,但C#程序调用执行慢的问题
    Centos8.0 安装Mongodb 命令步骤
    $TeX$ Gyre 字体安装过程与问题解决
    tomcat部署项目
    登录嵌套
    Django基础之
    win 常用命令
  • 原文地址:https://www.cnblogs.com/daxueshan/p/6321904.html
Copyright © 2020-2023  润新知