2
votes

Ok so this is kind of a strange issue, but I have got two scrollViews that each have a nested imageView so as to allow for panning and zooming of an image. The tow scrollView/imageView combo's are showing up just great, and because the image is bigger than my scrollView size, I can pan just great. Here is my viewDidLoad:

-(void) viewDidLoad
{
// set the image to be displayed, pic your own image here

imageView = [[MyImage alloc] initWithImage: [UIImage imageNamed: @"newBackground.png"]];

// yes we want to allow user interaction

[imageView setUserInteractionEnabled:YES];

// set the instance of our myScrollView to use the main screen

scrollView = [[MyScroll alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

// turn on scrolling

[scrollView setScrollEnabled: YES];

// set the content size to the size of the image

[scrollView setContentSize: imageView.image.size];

// add the instance of our myImageView class to the content view

[scrollView addSubview: imageView];

// flush the item

[imageView release];

// set max zoom to what suits you

[scrollView setMaximumZoomScale:1.0f];

// set min zoom to what suits you

[scrollView setMinimumZoomScale:0.25f];

// set the delegate

[scrollView setDelegate: self];

// scroll a portion of image into view (my image is very big) :)

//[scrollView scrollRectToVisible:CGRectMake(100, 100, 320, 440) animated:NO];

// yes to autoresize

scrollView.autoresizesSubviews = YES;

// set the mask

scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

// set the view

//self.view =scrollView;

[scrollView setFrame:CGRectMake(0, 0, 320, 230)];

[self.view addSubview:scrollView];


imageView1 = [[MyImage alloc] initWithImage: [UIImage imageNamed: @"newBackground.png"]];

// yes we want to allow user interaction

[imageView1 setUserInteractionEnabled:YES];

// set the instance of our myScrollView to use the main screen

scrollView1 = [[MyScroll alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

// turn on scrolling

[scrollView1 setScrollEnabled: YES];

// set the content size to the size of the image

[scrollView1 setContentSize: imageView1.image.size];

// add the instance of our myImageView class to the content view

[scrollView1 addSubview: imageView1];

// flush the item

[imageView1 release];

// set max zoom to what suits you

[scrollView1 setMaximumZoomScale:1.0f];

// set min zoom to what suits you

[scrollView1 setMinimumZoomScale:0.25f];

// set the delegate

[scrollView1 setDelegate: self];

// scroll a portion of image into view (my image is very big) :)

//[scrollView scrollRectToVisible:CGRectMake(100, 100, 320, 440) animated:NO];

// yes to autoresize

scrollView1.autoresizesSubviews = YES;

// set the mask

scrollView1.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

// set the view

//self.view =scrollView;

[scrollView1 setFrame:CGRectMake(0,240,320,230)];


[self.view addSubview:scrollView1];
//[[self view] addSubview:scrollView];

}

No as for zooming, when I pinch to zoom on the FIRST scrollView/imageView pair, it works beautifully, no problems whatsoever. It zooms and pans no problem. BUT when I pinch to zoom my second scrollView, it pans the image of the SECOND, and zooms the image of the FIRST. SO my SECOND scrollView zooms the FIRST's image. Huh? I have no idea why that would be happening.

All I want is to have to separate images viewed that can be independently panned and zoomed.

Any thoughts as to what might be happening?

Thanks!

1

1 Answers

1
votes

Your viewForZoomingInScrollView: method is probably returning the same image view for both scroll views. It needs to look at which scroll view is being passed in and return the corresponding image view.