I made an UIScrollView with pages. On Each page I will have an UIScrollView with UIImageView. I want to handle zooming of the images on each page in this way. But zooming delegate method is not being called.
Here is my code:
verticalScroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
horizontalScroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
verticalScroll.backgroundColor=[UIColor purpleColor];
verticalScroll.pagingEnabled=YES;
verticalScroll.contentSize=CGSizeMake(768*[largeImagesFromGallery count], 1024);
horizontalScroll.backgroundColor=[UIColor blackColor];
horizontalScroll.pagingEnabled=YES;
horizontalScroll.contentSize=CGSizeMake(1024*[largeImagesFromGallery count], 768);
float cofVert=1.34f;
for(int i=0; i<[largeImagesFromGallery count]; i++)
{
UIImage *temp=[largeImagesFromGallery objectAtIndex:i];
UIScrollView *svVert=[[UIScrollView alloc] initWithFrame:CGRectMake(i*768, 0, temp.size.width/cofVert, temp.size.height/cofVert)];
svVert.contentSize=CGSizeMake(temp.size.width/cofVert, temp.size.height/cofVert);
svVert.zoomScale=3.0f;
svVert.delegate=self;
UIImageView *imageVert=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, temp.size.width/cofVert, temp.size.height/cofVert)];
imageVert.image=temp;
imageVert.tag=2000;
UIScrollView *svHor=[[UIScrollView alloc] initWithFrame:CGRectMake(i*1024, 0, temp.size.width, temp.size.height)];
svHor.delegate=self;
svHor.contentSize=CGSizeMake(temp.size.width, temp.size.height);
UIImageView *imageHor=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, temp.size.width, temp.size.height)];
imageHor.image=temp;
imageHor.tag=2000;
[svVert addSubview:imageVert];
[svHor addSubview:imageHor];
[verticalScroll addSubview:svVert];
[horizontalScroll addSubview:svHor];
//fr=CGRectMake(0, 0, 768, 1024);
//[verticalScroll addSubview:imageVert];
// [horizontalScroll addSubview:imageHor];
}
//verticalScroll.delegate=self;
// horizontalScroll.delegate=self;
ambiancesON=YES;
if(self.interfaceOrientation==UIInterfaceOrientationPortrait || self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
[self.view addSubview:verticalScroll];
}
else if(self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
[self.view addSubview:horizontalScroll];
}
So now I have zoom method:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
NSLog(@"Log log log");
NSLog(@"VIew? %@", [[scrollView subviews]objectAtIndex:0]);
return [[scrollView subviews]objectAtIndex:0];
}
Zoom is not being called((
I think there is a flaw in your design. I would recommend creating a view controller class for each of the inner scrollviews (the ones you want to respond to the zoom). That way, if everything is wired correctly (UIScrollView delegates are assigned to the inner view controller), it should work as you expect.