UIScrollView - programmatically setting zoom

Discussion in 'iOS Programming' started by Taum, Aug 4, 2008.

  1. Taum macrumors member

    Jul 28, 2008

    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.
  2. Sbrocket macrumors 65816


    Jun 3, 2007
    Just change the scale of the view controlled by the UIScrollView, animating if necessary.
  3. Taum thread starter macrumors member

    Jul 28, 2008
    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 ?

Share This Page