原图: 900 x 1305
拖曳滚动:
缩放:
主要代码:
//
// ViewController.m
// ImageZoom
//
// Created by hellovoidworld on 14/11/28.
// Copyright (c) 2014年 hellovoidworld. All rights reserved.
// #import "ViewController.h" @interface ViewController () // 图片控件
@property (weak, nonatomic) IBOutlet UIImageView *imageView; // UIScrollView控件
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. self.scrollView.contentSize = CGSizeMake(, );
self.scrollView.delegate = self; self.scrollView.maximumZoomScale = 2.0;
self.scrollView.minimumZoomScale = 0.1; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
NSLog(@"开始拖曳");
} - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"正在拖曳");
} - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
NSLog(@"结束拖曳");
} // 缩放手势调用的方法
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return self.imageView; // 需要放大的ImageView
} - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view {
NSLog(@"开始缩放");
} - (void)scrollViewDidZoom:(UIScrollView *)scrollView {
NSLog(@"正在缩放");
} - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale {
NSLog(@"结束缩放");
} - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
NSLog(@"拖曳完成后减速开始");
} - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
NSLog(@"拖曳完成后减速完成");
} @end