从 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];