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

  没啥难的,直接上代码:

//

//  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

iOS开发——点击图片全屏显示的更多相关文章

  1. HBuilder开发iPad程序不能全屏显示的解决方法

    HBuilder开发iPad程序不能全屏显示的解决方法: targets选择HBuilder=>Deployment Info=> devices选择Universal即可

  2. 微信小程序点击图片全屏

    作为一个只懂简单HTML,jQuery,JS的web后台开发者,最近在学习小程序开发,现在将小程序的点击全屏功能的相关内容记录下来.如果有不对的地方或者有更简单的方法,请留言指教 0_0~ .js 文 ...

  3. Xcode 设置图片全屏显示

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...

  4. banner图片全屏显示

    <script> $(function () { function reinitSize() { var window_h = $(window).height(); var window ...

  5. HTML设置body背景图片全屏显示

    在head标签中添加body属性设置: <head><style>body{background:url(timg1.jpg) top left;background-size ...

  6. IOS应用在ios7(iPhone5/iPhone5s)上不能全屏显示

    前言 [IOS应用在iOS7系统或者iPhone5/iPhone5s上不能全屏显示,应用画面上下各有1条黑色,但是在其他系统或者型号的手机上却是正常显示 Paste_Image.png Paste_I ...

  7. 在VC++6.0开发中实现全屏显示

    全屏显示是一些应用软件程序必不可少的功能.比如在用VC++编辑工程源文件或编辑对话框等资源时,选择菜单“View\Full Screen”,即可进入全屏显示状态,按“Esc”键后会退出全屏显示状态. ...

  8. Android开发之全屏显示的两种方法

    1.通过修改清单文件中Theme,实现全屏 <application android:name=".MyApplication" android:allowBackup=&q ...

  9. Xamarin安卓开发:去掉Activity的头部标题栏及全屏显示

    http://blog.csdn.net/u012234115/article/details/35814209 以下是用修改布局文件的方法,其实还有用C#代码的方法. 打开AndroidManife ...

随机推荐

  1. AI 人工智能 探索 (二)

    完整被动技能代码 using UnityEngine; using System.Collections; public class AI : MonoBehaviour { private Hash ...

  2. js对象大总结2016/4/19

    本地对象(非静态对象) 常用的对象Object,Funcion,Array,Boolen,String,Boolen,Number,Date,RegEXP,Error;new一下就能用的 内置对象:( ...

  3. html 7.28

    1.HTML标记在没有添加任何样式的时候,默认是有间距的,所以我们要先把把所有标记归置内(padding)外(margin)边距归置为0 2.HTML5 中不支持 <acronym> 标签 ...

  4. JS定时器的使用--无缝滚动

    <title>无标题文档</title> <style> * {margin:0; padding:0;} #div1{width:1172px; height:2 ...

  5. stray '/241' in program 错误

    意思是c/c++中的编译错误. 该错误是指源程序中有非法字符,需要去掉非法字符.一般是由于从别的地方粘贴过来造成的. 方法:1.把所粘的文字放到记事本里就行了 2.把出错行的空格删掉重新打一下试试.

  6. Linux学习 -- Shell基础 -- 概述

    Shell是什么? 命令解释器 编程语言 Linux支持的Shell类型 cat /etc/shells 主要学习 bash 脚本执行方式 echo echo -e 单引号 -- 原始字符串  双引号 ...

  7. PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)

    简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  8. mysql分页pagination

    http://www.phpjabbers.com/php--mysql-select-data-and-split-on-pages-php25.html returns 20 records so ...

  9. php使用curl提交xml数据

    $xml_data ='<xml> <return_code><![CDATA[SUCCESS]]></return_code> <return_ ...

  10. Entity Framework 学习初级篇6--EntityClient

    System.Data.EntityClient 命名空间是 实体框架的 .NET Framework 数据提供程序.EntityClient 提供程序使用存储特定的 ADO.NET 数据提供程序类和 ...