0

I am adding many UIImageView's to UIScrollView,with paging enabled.I need to zoom only the image that i have tapped to zoom,rather than zooming the entire scrollview.Also zooming a particular image doesnot scale other subviews.

- (void)loadScrollViewWithImages {

scrollView.contentSize = CGSizeMake(self.view.bounds.size.width * imageList.count, self.view.bounds.size.height);
scrollView.pagingEnabled = YES;
UIView *mainView = [[UIView alloc] initWithFrame:self.view.bounds];

CGFloat xPos = 0.0;
for (UIView *subView in scrollView.subviews) {
    [subView removeFromSuperview];
}

int i = 0;

for (NSDictionary *imageDetails in self.imageList) {

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xPos, 0.0, self.view.bounds.size.width, self.view.frame.size.height)];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    [imageView setClipsToBounds:YES];
    [mainView addSubview:imageView];
    xPos += self.view.bounds.size.width;

    [imageView setImageWithURL:[NSURL URLWithString:[imageDetails objectForKey:@"media_path"]]];

    [self.imageViewArray addObject:imageView];

    if(self.selectedImageIndex == i) {
        self.selectedImageView = imageView;
    }
    i++;
}
[mainView setFrame:CGRectMake(mainView.frame.origin.x, mainView.frame.origin.x,self.view.bounds.size.width * imageList.count, self.view.bounds.size.height)];
[scrollView addSubview:mainView];

}

I wanted to zoom only the selected index,but other subviews also add to the screen with no scaling.

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [[[scrollView.subviews objectAtIndex:0] subviews] objectAtIndex:0] ;;

}

Nassif
  • 1,113
  • 2
  • 14
  • 34

1 Answers1

0

for implementing this you have to take a main scrollview as you have taken and instead of displaying imageView in this scrollview you have to take another scrollview and display the image and when user tries to zoom the image then only the selected scrollview gets scrolled.

Manish Agrawal
  • 10,958
  • 6
  • 44
  • 76