UIScrollView中实现图片的放大缩小

UIScrollView中实现图片的放大缩小

img=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"aa.png"]];
    scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(60, 60, 200, 200)];
    [scrollView setBackgroundColor:[UIColor grayColor]];
    scrollView.contentSize=CGSizeMake(img.image.size.width, img.image.size.height);
    scrollView.minimumZoomScale=0.1;
    scrollView.maximumZoomScale=2.0;
    
    scrollView.showsHorizontalScrollIndicator=YES;
    scrollView.showsVerticalScrollIndicator=YES;
    scrollView.bounces=NO; //反弹效果
    scrollView.alwaysBounceVertical=YES;
    scrollView.alwaysBounceHorizontal=YES;
    scrollView.delegate=self;
    [self.view addSubview:scrollView];
    [self.scrollView addSubview:img];

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return img;//UIImageView对象
}


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