• iOS开发——点击图片全屏显示


      点击图片,全屏显示,然后再点击屏幕一下,返回。

      没啥难的,直接上代码:

    //

    //  ViewController.m

    //  Demo-hehe

    //

    //  Created by yyt on 16/4/25.

    //  Copyright © 2016年 yyt. All rights reserved.

    //

    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 80, self.view.bounds.size.width-40, 300)];

        imageView.image = [UIImage imageNamed:@"11"];

        imageView.userInteractionEnabled = YES;

        [self.view addSubview:imageView];

        

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

        tapGesture.numberOfTapsRequired=1;

        [imageView addGestureRecognizer:tapGesture];

    }

    //缩放图片

    -(void)showZoomImageView:(UITapGestureRecognizer *)tap

    {

        if (![(UIImageView *)tap.view image]) {

            return;

        }

        

        UIView *bgView = [[UIView alloc] init];

        bgView.frame = [UIScreen mainScreen].bounds;

        bgView.backgroundColor = [UIColor blackColor];

        [[[UIApplication sharedApplication] keyWindow] addSubview:bgView];

        

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

        [bgView addGestureRecognizer:tapBgView];

        

        //必不可少的一步,如果直接把点击获取的imageView拿来玩的话,返回的时候,原图片就完蛋了

        UIImageView *tempImageView = (UIImageView*)tap.view;

        

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:tempImageView.frame];

        imageView.image = tempImageView.image;

        [bgView addSubview:imageView];

        

        [UIView animateWithDuration:0.5 animations:^{

            CGRect frame = imageView.frame;

            frame.size.width = bgView.frame.size.width;

            frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);

            frame.origin.x = 0;

            frame.origin.y = (bgView.frame.size.height - frame.size.height) * 0.5;

            imageView.frame = frame;

        }];

    }

    -(void)tapBgView:(UITapGestureRecognizer *)tapBgRecognizer

    {

        [tapBgRecognizer.view removeFromSuperview];

    }

    @end

  • 相关阅读:
    一文带你了解接口测试价值与体系
    干货|app自动化测试之设备交互API详解
    干货|app自动化测试之Appium问题分析及定位
    干货| app自动化测试之Andriod微信小程序的自动化测试
    如果你也有这些职场困惑,周六一直线上答疑
    文末福利 | 团队管理第一步之高效招聘
    精准化测试原理简介与实践探索
    文末有福利 | 面试时如何命中面试官的考题?
    Visual studio prebuild/postbuild 设置条件不生效
    使用腾讯地图api获取定位信息经纬度(需要浏览器支持,且需要https)
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/5431650.html
Copyright © 2020-2023  润新知