2015-08-20 46 views
0

我從ALAssetLibrary.My獲取後顯示圖像有問題如果有一個圖像,那麼它會很好,但如果有多個圖像,那麼最後一個圖像是隻出現,但不是先前的圖像。我發現在循環中存在問題並且無法找到是否。添加多個UIImages從ALAssetLibrary中啓用尋呼啓用UIScrollView

請讓我知道,如果有人解決這個問題。

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

在這裏,您沒有設置滾動視圖的內容大小。

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

還需要在添加到scrollView之前更改每個imageView的X偏移量(如果水平滾動)。

此外,您沒有添加imageForZooming任何滾動視圖在這裏。

here從ALAssetLibrary加載圖像。

+0

我設置了滾動,它與滾動視圖的寬度,運作良好,但圖像沒有出現在it.Only問題使用ALAssetLibrary Code.the else條件時,工作正常,與多個images.But不符合的contentSize ASSETLibrary條件。 –

+0

請通過編輯的代碼,讓我知道是什麼問題。 –

+0

您是否在說:「如果您使用ALAssetLibrary,並且所有圖像都以其他情況顯示,只顯示最後一張圖像?」 – Dev