Objective-c – UIScrollView setZoomScale not working

cocoa-touchobjective cuikit

I am struggeling with my UIScrollview to get it to zoom-in the underlying UIImageView. In my view controller I set

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

In the viewDidLoad method I try to set the zoomScale to 2 as follows (note the UIImageView and Image is set in Interface Builder):

- (void)viewDidLoad {
 [super viewDidLoad];

 myScrollView.contentSize = CGSizeMake(myImageView.frame.size.width, myImageView.frame.size.height);
 myScrollView.contentOffset = CGPointMake(941.0, 990.0);
 myScrollView.minimumZoomScale = 0.1;
 myScrollView.maximumZoomScale = 10.0;
 myScrollView.zoomScale = 0.7;
 myScrollView.clipsToBounds = YES;
 myScrollView.delegate = self;

 NSLog(@"zoomScale: %.1f, minZoolScale: %.3f", myScrollView.zoomScale, myScrollView.minimumZoomScale);
}

I tried a few variations of this, but the NSLog always shows a zoomScale of 1.0.

Any ideas where I screw this one up?

Best Answer

I finally got this to work. what caused the problem was the delegate call being at the end. I now moved it up and .... here we go.

New code looks like this:

- (void)viewDidLoad {
 [super viewDidLoad];

 myScrollView.delegate = self;
 myScrollView.contentSize = CGSizeMake(myImageView.frame.size.width, myImageView.frame.size.height);
 myScrollView.contentOffset = CGPointMake(941.0, 990.0);
 myScrollView.minimumZoomScale = 0.1;
 myScrollView.maximumZoomScale = 10.0;
 myScrollView.zoomScale = 0.7;
 myScrollView.clipsToBounds = YES;
}