0

i am having a problem with showing images after fetching from the ALAssetLibrary.My Problem is if there is one image then its coming fine but if there are multiple images then the last image is only appearing but not the prior images.I fount that there is a problem in the Loop and couldn't find if.

Please let me know if anyone resolve this.

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];
beresfordt
  • 5,088
  • 10
  • 35
  • 43
Ajay Babu
  • 1
  • 2

1 Answers1

0

Here you didn't set the content size of the scroll view.

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

And also you have to change the X offset (If horizontal scrolling) for each imageView before adding to scrollView.

Also, you didn't add imageForZooming to any scrollView here.

Look here to load the images from ALAssetLibrary.

Dev
  • 1,215
  • 9
  • 17
  • I set the contentSize of the Scrollview,its working well with the width of the Scroll View but images are not appearing on it.Only problem when using ALAssetLibrary Code.the Else condition is working fine with multiple images.But not with The ASSetLibrary Condition. – Ajay Babu Aug 20 '15 at 10:39
  • Please go through the edited code and let me know what is the issue. – Ajay Babu Aug 20 '15 at 10:55
  • Are you saying "Only last image is showing if you use ALAssetLibrary and all images are getting shown in else condition?" – Dev Aug 20 '15 at 11:07
  • I found that ALAssetLybrary is working Asynchronously and it seems there is something missing out here for the proper adding of the images to the imageforZooming object. – Ajay Babu Aug 20 '15 at 11:07
  • Yes,my Problem is the what you said. – Ajay Babu Aug 20 '15 at 12:29
  • With ALAssetLibrary i can able to see only last image and all images are not appearing but the uiimage Objects are added to the ImageView with out images.But the same thing works perfectly when else condition is executing. – Ajay Babu Aug 20 '15 at 12:32
  • Once look at the link I provided in answer. – Dev Aug 20 '15 at 12:53