图片放大缩小

导入一张图片

<UIScrollViewDelegate>

@property (nonatomic,strong)UIScrollView * scrollView;

@property (nonatomic,strong)UIImageView *imageView;


//===============

- (void)viewDidLoad {

[super viewDidLoad];

         [self createView];

}

//===================


-(void)createView

{

_scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64)];

[self.view addSubview:_scrollView];

_imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 64)];

_imageView.image = [UIImage imageNamed:@"05-022927_250.jpg"];

_imageView.contentMode = UIViewContentModeScaleAspectFit;

[_scrollView addSubview:_imageView];

//设置内容大小

_scrollView.contentSize = _imageView.frame.size;

//设置代理为控制器

_scrollView.delegate = self;

//设置最小缩放比例

_scrollView.minimumZoomScale = 1;

//设置最大缩放比例

_scrollView.maximumZoomScale = 2;

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

//设置手势点击数,双击:点2下

tapGesture.numberOfTapsRequired=2;

//    self.imageView.userInteractionEnabled = YES;

[_scrollView addGestureRecognizer:tapGesture];

//    [self.imageView addGestureRecognizer:tapGesture];

}

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

//放大缩小

-(void)handleTapGesture:(UIGestureRecognizer*)sender

{

if(_scrollView.zoomScale > 1.0){

[_scrollView setZoomScale:1.0 animated:YES];

}else{

[_scrollView setZoomScale:2.0 animated:YES];

}

}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

{

return _imageView;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容