PDA

View Full Version : UIScrollView - programmatically setting zoom




Taum
Aug 4, 2008, 05:38 PM
hi,

I've looked thru the docs but can't find a way to set the zoom to an arbitrary value. Am I missing something obvious ?
I'd like the scrollview to zoom in as I double tap it. I can get the double tap but I'm stuck after that.



Sbrocket
Aug 4, 2008, 06:14 PM
hi,

I've looked thru the docs but can't find a way to set the zoom to an arbitrary value. Am I missing something obvious ?
I'd like the scrollview to zoom in as I double tap it. I can get the double tap but I'm stuck after that.

Just change the scale of the view controlled by the UIScrollView, animating if necessary.

Taum
Aug 5, 2008, 05:28 AM
Thanks for your reply :)
Could you explain a little bit more what you mean by "the scale of the view" ? There is no scale property for UIView, nor could I see anything related in UIScrollView. I did try to change the transform of the view, which almost work, but it sounds like UIScrollView isn't aware of this change.

Here is what I'm doing in my UIScrollView subclass (I'm not interested in animation for now, I just try to set the zoom to 8x and center the view) :
UIView *v = [self.delegate viewForZoomingInScrollView:self];
int vw = v.bounds.size.width;
int vh = v.bounds.size.height;
CGAffineTransform t = v.transform;
t = CGAffineTransformMakeScale(8, 8);
v.transform = t;
v.center = CGPointMake(vw*4, vh*4);
self.contentSize = CGSizeMake(vw*8, vh*8);
[self setContentOffset:CGPointMake(vw*4, vh*4) animated:NO];

[self.delegate scrollViewDidEndZooming:self withView:v atScale:8];

When I double tap, it does zoom to 8x and I can pan, but if I zoom in or out using pinching it breaks as if the UIScrollView didn't knew I changed the scale myself (and how should it know, unless it checked v.transform before zooming ?). Did I miss something ?