`
zheyiw
  • 浏览: 997226 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics