uiimageview uiscroll 图片的缩放


-(void)loadImage{    
    // Create a scroll view
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 390)];
    scrollView.delegate = self;
    scrollView.bouncesZoom = YES;
    scrollView.backgroundColor = [UIColor whiteColor];
    
    CGFloat maximumWidth = 320;
    CGFloat totalHeight = 0.0;
    UIImage *image = [UIImage imageNamed:@"shopcart_no.png"];
    CGRect frame = CGRectMake(0, 0, 320, 390);
    imageView = [[UIImageView alloc] initWithFrame:frame];
    imageView.image = image;
    [imageView setContentMode:UIViewContentModeCenter];
    
    // Increment our maximum width & total height
    maximumWidth = MAX(maximumWidth, image.size.width);
    totalHeight += image.size.height;

    scrollView.minimumZoomScale = scrollView.frame.size.width / maximumWidth;
    scrollView.maximumZoomScale = 2.0;
    
    [scrollView addSubview:imageView];
    [self.view addSubview:scrollView];   
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return imageView;
}

猜你喜欢

转载自zheyiw.iteye.com/blog/1685248