Before describing my problem a very basic question,is there a way can we return UIScrollView object from this method
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
Now my problem is, I have a parent scrollview with multiple child scrollview inside it(all horizontal and paging enabled).
Each child scrollview has an ImageView. I am getting zoomScale factor from server and based on the image, I have to zoom it, The problem is when I try to zoom a child scrollView which has image inside it,it only zooms the last child scrollview.
So I think, I need to find out a way where we can return a scrollview form the above written delegate.
Anyone an idea how to solve this?
THis is UIView Class and i added scrollView and image on this and returned imageView For scrollView Delegate
SAMPLE CODE:
- (id)initWithFrame:(CGRect)frame image:(UIImage *)image
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor=[UIColor yellowColor];
self.imageView = [[UIImageView alloc] initWithImage:image];
self.imageView.tag = VIEW_FOR_ZOOM_TAG;
self.imageView.frame=frame;//CGRectMake(8,8 ,305, 400);
[self.imageView setContentMode:UIViewContentModeScaleAspectFit];
self.scrollView = [[UIScrollView alloc] initWithFrame:frame];
self.scrollView.minimumZoomScale = 0.4f;
self.scrollView.maximumZoomScale = 2.0f;
self.scrollView.backgroundColor=[UIColor redColor];
self.scrollView.zoomScale = 1.0f;
self.scrollView.contentSize = self.imageView.bounds.size;
self.scrollView.delegate = self;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
[self.scrollView setCanCancelContentTouches:NO];
[self.scrollView addSubview:self.imageView];
[self addSubview:self.scrollView];
NSLog(@"ScrollViewPostion %f",self.scrollView.frame.origin.x);
}
return self;
}
#pragma -mark
#pragma -mark ScrollViewDelegates
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [scrollView viewWithTag:VIEW_FOR_ZOOM_TAG];
}
And in my main viewController class i am doing this but its not adding all the images properly in the scrollview
NSLog(@"Inner scrollFrame and content size %f %f",innerScrollFrame.origin.x,mainScrollView.contentSize.width);
JoinSeeSubView *subView=[[JoinSeeSubView alloc] initWithFrame:innerScrollFrame image:img];
[self.mainScrollView addSubview:subView];
if (i < [self.allUrlArray count]-1) {
innerScrollFrame.origin.x += innerScrollFrame.size.width;
}
i++;
mainScrollView.contentSize = CGSizeMake(innerScrollFrame.origin.x + innerScrollFrame.size.width, mainScrollView.bounds.size.height);
In case the above approach didn’t help someone really in need,I solved this problem in a different way,but not sure if it is correct way to do this.
So instead of creating a new class which extends UIView,I create and array and store all the objects of inner scrollview in that array.So my code look something like
And whenever i need to access a particular imageview contained inside scrollview i do this :-
But as i said earlier i don’t know how efficient this code is,but its been more than a month the app is on store and being tested properly ,yet no issue because of this.