我有一个从NSURL加载的图像数组,以滚动并捏缩放。我能够实现滚动部分,但是当我尝试将任何图像缩放到第一个图像之外时,滚动就会卡住,图像上的比例也会卡住。这是我的代码:

 scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, self.view.bounds.size.height)];
scrollView.showsHorizontalScrollIndicator = FALSE;
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = 1.0;
scrollView.delegate = self;
[self.view addSubview:scrollView];


for (int i=0; i<[listOfImagesZoom count]; i++) {
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(leftMargin, self.scrollView.bounds.origin.y-100, SCREEN_WIDTH, self.view.bounds.size.height-100)];
    // [imageView setImage:[UIImage imageNamed:@"img_def.png"]];
    NSString *urlImage1 = (NSString*)[listOfImagesZoom objectAtIndex:i];
    NSString *productImageURL1 = [urlImage1 stringByReplacingOccurrencesOfString:@"~" withString:@""];
    NSString *productImageURL2 = [productImageURL1 stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    NSString* urlImage = [NSString stringWithFormat:@"http://sagana-ideas.azurewebsites.net%@", productImageURL2];
    NSURL *imgURL=[NSURL URLWithString:urlImage];

    [imageView setImageWithURL:imgURL placeholderImage:[UIImage imageNamed:@"ex_product.png"]];

    imageView.contentMode = UIViewContentModeScaleAspectFit;


    [scrollView addSubview:imageView];
    [imageView setUserInteractionEnabled:NO];
    imageView.tag = i;

    leftMargin += SCREEN_WIDTH;


}
[scrollView setContentSize:CGSizeMake(leftMargin, 0)];
[scrollView setPagingEnabled:YES];
scrollView.delegate = self;


我什至已经实施了

 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

    {

        return imageView;
    }


如果仅要加载单个图像,则该功能有效,但是当图像数量超过1个时,该功能将卡住。

最佳答案

您需要ScrollView才能显示图像列表。每个图像都显示一个scrollView(子类scrollview)以执行放大/缩小。
尝试看一下:MWPhotoBrowser

关于ios - 放大UIScrollView-无法缩放到单个图像之外并滚动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22525605/

10-10 17:36
查看更多