图像数组在UIScrollview和Paging中成功显示,但无法在scrollview中正确放大图像 [英] Array of Images display in UIScrollview and Paging successfully but cannot properly zoom-in images in scrollview

查看:125
本文介绍了图像数组在UIScrollview和Paging中成功显示,但无法在scrollview中正确放大图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ImageArray处理UIScrollview。滚动和分页工作正常,但我无法缩放每个图像。我的图像代码Scrollview如下: -

I am working on UIScrollview with ImageArray. Scrolling and paging are working but I not able to zoom each image. My code of image Scrollview is below :-

#define IMAGE_WIDTH 320

#define IMAGE_HEIGHT 360

 - (void)viewDidLoad
 {
[super viewDidLoad];

// TODO – fill with your photos
NSArray *photos = [[NSArray arrayWithObjects:
                    [UIImage imageNamed:@"photo1m.jpg"],
                    [UIImage imageNamed:@"photo2m.jpg"],
                    [UIImage imageNamed:@"photo3m.jpg"],
                    [UIImage imageNamed:@"photo4m.jpg"],
                    nil] retain];
// note that the view contains a UIScrollView in aScrollView

    int i=0;
    for ( NSString *image in photos )
    {
       UIImage *images = [photos objectAtIndex:i];
       imageView = [[UIImageView alloc] initWithImage:images];
       imageView.contentMode = UIViewContentModeScaleAspectFit;
       imageView.clipsToBounds = YES;

       imageView.frame = CGRectMake( IMAGE_WIDTH * i++, 0, IMAGE_WIDTH, IMAGE_HEIGHT);

       [self.scrollViewimages addSubview:imageView];
      [imageView release];
     }
      self.scrollViewimages.contentSize = CGSizeMake(IMAGE_WIDTH*i, IMAGE_HEIGHT);
      self.scrollViewimages.delegate = self; 
 }

需要帮助实现每张图像的缩放缩放。请帮忙!

Need to help for implementing pinch zoom of every images. Please help !

推荐答案

for ( NSString *image in photos )
    {
       UIImage *images = [photos objectAtIndex:i];
       imageView = [[UIImageView alloc] initWithImage:images];
       imageView.contentMode = UIViewContentModeScaleAspectFit;
       imageView.clipsToBounds = YES;
       imageView.tag = 1;

       UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake( IMAGE_WIDTH * i++, 0, IMAGE_WIDTH, IMAGE_HEIGHT)];
       scrollView.delegate = self;
       scrollView.maximumZoomScale = 3.0f
       imageView.frame = scrollView.bounds;
       [scrollView addSubview:imageView];
       [imageView release];

       [self.scrollViewimages addSubview:scrollView];

     }

并在UIScrollViewDelegate中实现委托方法

And Implement the delegate method in UIScrollViewDelegate

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return [scrollView viewWithTag:1];
}

这篇关于图像数组在UIScrollview和Paging中成功显示,但无法在scrollview中正确放大图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆