views:

52

answers:

1

Hi, I have an image that I want to load into an image view and set the minimumZoomScale, as well as the zoomScale to an aspectFill like scale that I calculate as follows:

// configure the map image scroll view
iImageSize = CGSizeMake(iImageView.bounds.size.width, iImageView.bounds.size.height);
iScrollView.minimumZoomScale = iScrollView.bounds.size.height / iImageSize.height;
iScrollView.maximumZoomScale = 2;
iScrollView.zoomScale = iScrollView.minimumZoomScale;
iScrollView.contentOffset = CGPointMake(0, 0);
iScrollView.clipsToBounds = YES;

The iScrollView size is 450 x 320px and the iImageSize is 1600 x 1960px.

Doing the minimumZoomScale math by hand: 450 / 1960 = 0.22959184. The system determines 0.234693885 instead (???).

But to get the window fit into the 450px space, both figures don't work (!!!). I manually tried and found 0.207 is the right number (that would translate to a image height of 2174 xp or alternatively a UIScrollView height of 406px).

For information: the UIScrollview screen is 450px, namely 480px minus status bar height (10), minus UITabBar height (20)

Any clues on this misbehaviour?

+1  A: 

For simple zoom in/out i generally use below code. minimumZoomScale= 1 sets initial zoom to current image size. I have given maximumZoomScale = 10 which can be calculated from actual ratio of image size and container frame size.

[scrollView addSubview: iImageView];
    scrollView.contentSize = iImageView.frame.size;
    scrollView.minimumZoomScale = 1.0;
    scrollView.maximumZoomScale = 10;
    [iImageView setFrame:CGRectMake(0, 0, 450, 320)];
[scrollView scrollRectToVisible:iImageView.frame animated:YES];
Avinash