ITeye博客

uiimageview uiscroll 图片的缩放

zheyiw · 2012-09-25 18:01 · Iphone · 移动开发 · Markdown



-(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;
}


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。