iOS图片查看,UIScrollView,放大,缩小,单机和双击

////  ImageVC.h//  MovieCrowdfunding////  Created by Sun-Mac on 2016/11/1.//  Copyright © 2016年  All rights reserved.//#import@interface ImageVC : UIViewController

@property(strong,nonatomic)NSURL *imageURL;//创建vc对象之后要传imageURL

@end


//

//  ImageVC.m

//  MovieCrowdfunding

//

//  Created by Sun-Mac on 2016/11/1.

//  Copyright © 2016年 . All rights reserved.

//

#import "ImageVC.h"

@interface ImageVC ()

{

UIScrollView *scrollView;

UIImageView *imageView;

}

@end

@implementation ImageVC

- (void)viewDidLoad

{

[super viewDidLoad];

self.view.backgroundColor = [UIColor blackColor];

scrollView=[[UIScrollView alloc]initWithFrame:self.view.bounds];

scrollView.maximumZoomScale=5.0;//图片的放大倍数

scrollView.minimumZoomScale=1.0;//图片的最小倍率

scrollView.contentSize=CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height);

scrollView.delegate=self;

imageView=[[UIImageView alloc]initWithFrame:self.view.bounds];

[imageView setImageWithURL:self.imageURL placeholderImage:[UIImage imageNamed:@"1"]];

[scrollView addSubview:imageView];

[self.view addSubview:scrollView];

imageView.userInteractionEnabled=YES;//注意:imageView默认是不可以交互,在这里设置为可以交互

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

tap.numberOfTapsRequired=1;//单击

tap.numberOfTouchesRequired=1;//单点触碰

[imageView addGestureRecognizer:tap];

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

doubleTap.numberOfTapsRequired=2;//避免单击与双击冲突

[tap requireGestureRecognizerToFail:doubleTap];

[imageView addGestureRecognizer:doubleTap];

imageView.contentMode=UIViewContentModeScaleAspectFit;

}

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView  //委托方法,必须设置  delegate

{

return imageView;//要放大的视图

}

-(void)doubleTap:(id)sender

{

scrollView.zoomScale=2.0;//双击放大到两倍

}

- (IBAction)tapImage:(id)sender

{

[self dismissViewControllerAnimated:YES completion:nil];//单击图像,dismissViewController

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • { 11、核心动画 需要签协议,但是系统帮签好 一、CABasicAnimation 1、创建基础动画对象 CAB...
    CYC666阅读 5,551评论 2 4
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 7,438评论 1 14
  • 转自:http://www.code4app.com/blog-866962-1317.html1、设置UILab...
    MMOTE阅读 5,773评论 1 1
  • 今天和小表妹聊天,开始我们在聊单反和微单,后来她开始评价朋友圈里面我用手机拍的照片。最后她强烈建议我深度研究一下构...
    回音故事阅读 3,359评论 0 1
  • 冷诗 错异时空空悲叹 唯有靡靡独饮寒 若然回首美轮奂 冷雨夜,旧故里,依稀海波澜
    子风__阅读 3,596评论 0 2

友情链接更多精彩内容