0

从 ALAssetLibrary 获取图像后,我在显示图像时遇到问题。我的问题是,如果有一个图像,那么它会很好,但如果有多个图像,那么最后一个图像只会出现,而不是之前的图像。我发现有循环中的问题,找不到是否。

如果有人解决此问题,请告诉我。

mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 70, self.view.frame.size.width, self.view.frame.size.height)];

mainScrollView.pagingEnabled = YES;

mainScrollView.delegate=self;
mainScrollView.showsHorizontalScrollIndicator = NO;
mainScrollView.showsVerticalScrollIndicator = NO;

CGRect innerScrollFrame = mainScrollView.bounds;

for (NSInteger i = 0; i < images.count; i++) {

    imageForZooming=[[UIImageView alloc]init];

    if ([maincheck isEqualToString:@"YES"]) {
        NSURL*url=[NSURL URLWithString:[images objectAtIndex:i]];

        [library assetForURL:url resultBlock:^(ALAsset *asset)
         {
             UIImage  *copyOfOriginalImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
             [imageForZooming setImage:copyOfOriginalImage];
         }
            failureBlock:^(NSError *error)
         {
             NSLog(@"the error is %@",error);
         }];
    }

    else{
        [imageForZooming setImageWithURL:[NSURL URLWithString:[images objectAtIndex:i]]];
    }

    UITapGestureRecognizer*t=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showblack:)];

    t.numberOfTapsRequired=1;

    imageForZooming.userInteractionEnabled=YES;

    [imageForZooming addGestureRecognizer:t];

    imageForZooming.frame=CGRectMake(0, 50, 320, 200);

    imageForZooming.contentMode=UIViewContentModeScaleAspectFit;

    imageForZooming.tag = VIEW_FOR_ZOOM_TAG;

    pageScrollView = [[UIScrollView alloc] initWithFrame:innerScrollFrame];
    pageScrollView.minimumZoomScale = 1.0f;
    pageScrollView.maximumZoomScale = 4.5f;
    pageScrollView.zoomScale = 1.0f;
    pageScrollView.contentSize = imageForZooming.bounds.size;
    pageScrollView.delegate = self;
    pageScrollView.showsHorizontalScrollIndicator = NO;
    pageScrollView.showsVerticalScrollIndicator = NO;

    [pageScrollView addSubview:imageForZooming];

    [mainScrollView addSubview:pageScrollView];

    if (i < images.count-1) {
        innerScrollFrame.origin.x += innerScrollFrame.size.width;
    }
}

mainScrollView.contentSize = CGSizeMake(innerScrollFrame.origin.x + innerScrollFrame.size.width,mainScrollView.bounds.size.height);

[self.view addSubview:mainScrollView];
4

1 回答 1

0

这里你没有设置滚动视图的内容大小。

[scrollView setContentSize:CGSizeMake(numberOfImages * scrollView.frame.size.width, scrollView.frame.size.width)];

在添加到 scrollView 之前,您还必须更改每个 imageView 的 X 偏移量(如果是水平滚动)。

此外,您没有在此处将 imageForZooming 添加到任何 scrollView 中。

这里从 ALAssetLibrary 加载图像。

于 2015-08-20T10:34:13.097 回答