Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView doesn't respond to setZoomScale:

What am I doing wrong? Here is how I create + populate my scrollView

    -(void)viewDidAppear:(BOOL)animated {

    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bigimage.jpg"]];
    imgView.contentMode = UIViewContentModeScaleAspectFit;

    scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    scrollView.contentSize = imgView.frame.size;

    scrollView.minimumZoomScale =  scrollView.frame.size.width / scrollView.contentSize.width * 0.99;
    scrollView.maximumZoomScale =  2;

    [self.view addSubview:scrollView];


[scrollView addSubview:imgView];

    [scrollView setZoomScale:0.5 animated:YES];
    NSLog(@"current zoomScale: %f", scrollView.zoomScale);
    [imgView release];
}

The NSLogged zoomScale is 1.0, and the image is clearly shown at full size. Pinch zoom does not do anything. I've tried almost everything I can find on the net, but everybody seems to be doing exactly this, and it works for them.

Help is vastly appreciated!

like image 813
Kenny Winker Avatar asked Nov 30 '09 04:11

Kenny Winker


1 Answers

A UIScrollView will not zoom unless it has its delegate property set to a valid UIScrollViewDelegate that responds to

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;

Check out  the documentation.

like image 71
Ed Marty Avatar answered Sep 21 '22 00:09

Ed Marty