码迷,mamicode.com
首页 > 移动开发 > 详细

iOS用UIScorllView实现两指缩放功能

时间:2015-08-30 19:47:05      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

    两指缩放功能不仅可以用UIPinchGestureRecognizer手势来实现,还能用UIScorllView来实现,UIScrollView可以轻松的实现最大与最小缩放值,以及滚动的效果。代码如下:


#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _scrollView.minimumZoomScale = 1.0;     // 最小缩放值
    _scrollView.maximumZoomScale = 10.0;    // 最大缩放值
    [_scrollView setZoomScale:_scrollView.minimumZoomScale];    // 初始时候的缩放值
    _scrollView.delegate = self;
    
    _imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image"]];
    _imageView.frame = self.view.frame;
    [_scrollView addSubview:_imageView];
}

#pragma mark - 返回需要缩放的控件
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return _imageView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
关键点就是调用 viewForZoomingInScrollView:代理方法,这里返回了需要缩放的控件。


Demo的GitHub地址:https://github.com/are1/UIScrollViewZoomScale

iOS用UIScorllView实现两指缩放功能

标签:

原文地址:http://my.oschina.net/are1OfBlog/blog/499239

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!