views:

657

answers:

2

I created a zoomable UIScrollView and added 100 subviews to it (tiled). The view scrolls perfectly left and right. However, I'd like to allow zooming.

To do so I read that my delegate needs to implement:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return ???;
}

I have seen examples that have only one subview to zoom, so they return that subview in that method. In my case, however, I have a lot more. What is the proper way to do the zooming?

I tried creating another UIView and adding the 100 subviews to that one. And then return that one view on the method above, but I doesn't work (it zooms but once it stops, it's not interactive any more).

A: 

I created the view where I added everything using:

UIView *zoomableView = [[UIView alloc] init];

without setting its frame.

The problem was solved when, after adding all the subviews to it, I set its frame to something large enough to accommodate all the tiled subviews.

Dimitris
A: 

Exactly,

This is what Apple also is mentioning in the Scroll View Programming Guide:

Just create a view, add all subviews to this view and add the newly created view as a single subview to the scrollview...

Then in the viewForZoomingInScrollView delegate method return the object at Index 0:

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [self.scrollView.subviews objectAtIndex:0];}
Lefteris
Yeah, I should have read the documents to begin with :)
Dimitris