我在从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];
答案 0 :(得分:0)
这里没有设置滚动视图的内容大小。
[scrollView setContentSize:CGSizeMake(numberOfImages * scrollView.frame.size.width, scrollView.frame.size.width)];
在添加到scrollView之前,您还必须为每个imageView更改X偏移(如果是水平滚动)。
此外,您没有将imageForZooming添加到此处的任何scrollView。
查看here以从ALAssetLibrary加载图像。