用scrollerView实现图片的放大缩小

在进行图片处理的过程中,经常遇到类似于图片缩放的需求,以前做个一个用pinch手势对imageView进行缩放的例子,demo下载

下面就scrollView自带的图片缩放功能进行简单的介绍:

首先实现UIScrollerViewDelegate协议,并设置其delegate

设置最大放大倍数:maximumZoomScale 为float类型 和

最小缩小倍数:minimumZoomScale

实现 - (UIView*)viewForZoomingInScrollerView:(UIScrollerVIew*)scroller{}方法即可

示例如下

scrollerView=[[UIScrollView alloc]initWithFrame:self.view.bounds];
    scrollerView.delegate=self;
    scrollerView.minimumZoomScale=0.5f;
    scrollerView.maximumZoomScale=2.0f;
    
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:self.view.bounds];
    [imageView setImage:[UIImage imageNamed:@"20091121014197_2.jpg"]];
    [scrollerView addSubview:imageView];
    
    [self.view addSubview:scrollerView];

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    for (id view in [scrollerView subviews]) {
        if ([view isKindOfClass:[UIImageView class]]) {
            return view;
        }
    }
    return  nil;
}


你可能感兴趣的:(用scrollerView实现图片的放大缩小)