zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    优先队列
    Problem W UVA 662 二十三 Fast Food
    UVA 607 二十二 Scheduling Lectures
    UVA 590 二十一 Always on the run
    UVA 442 二十 Matrix Chain Multiplication
    UVA 437 十九 The Tower of Babylon
    UVA 10254 十八 The Priest Mathematician
    UVA 10453 十七 Make Palindrome
    UVA 10163 十六 Storage Keepers
    UVA 1252 十五 Twenty Questions
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/5431650.html
Copyright © 2011-2022 走看看