Seb
Seb

Reputation: 545

Maximum zoom scale of a UIScrollView

Based on the Large Image Downsizing iOS sample code, I'm trying to set a maximum zoom scale to my UIScrollView in order to not have a too big image.

I understood that the maximumZoomScale native property of a UIScrollView refers to the zoomScale property in order to authorize to zoom more or not. But, in this sample code, the scale of the image is manage with a custom float imageScale and the zoomScale property of the UIScrollView is always 1.

I saw, in this sample code, that the maximum zoom scale is managed using this method :

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    imageScale *=scale;
    if( imageScale < maximumScale ) imageScale = minimumScale; // THIS IS THE LINE WHO AVOID TO ZOOM TOO MUCH BUT IT MAKES A REALLY UGLY BEHAVIOUR

    CGRect imageRect = CGRectMake(0.0f,0.0f,CGImageGetWidth(image.CGImage) * imageScale,CGImageGetHeight(image.CGImage) * imageScale);
    // Create a new TiledImageView based on new frame and scaling.
    frontTiledView = [[TiledImageView alloc] initWithFrame:imageRect image:image scale:imageScale]; 
    [self addSubview:frontTiledView];
    [frontTiledView release];
}

So I expect to find a solution which has the same behaviour that the UIScrollView native one. I tried to set the zoomScale to the value of the imageScale everytime I changed it in the code but it make a strange behaviour on the image so I can't use this method.

So, my question is :

Thanks a lot !

Upvotes: 1

Views: 2343

Answers (1)

Seb
Seb

Reputation: 545

I think I'm on the good way ! This code solved my problem !

if (imageScale > delegateAppli.params.zoomLevelAuthorized) self.maximumZoomScale = 1.0;
else self.maximumZoomScale = 1 + delegateAppli.params.zoomLevelAuthorized - imageScale;

Hoping my answer will help other people...

Upvotes: 2

Related Questions