How to Zoom out an image with keeping it in a center of the Scrollview
<p>In my application i need to capture an image with cam and then pass it to the imageView, which is used as a subView for a ScrollView.</p>

<p>The requirement is "the image must facilitate 1/4th size for zoom out and 3 times the size for zoom in".</p>

<p>Now the problem is that when i zoom out this image the image zooms out, but it doesn't hold its position in the center. it sets its position respective to the touches of finger.
(No double tap zooming is there, and not required too)</p>

<p>Below is the code..,</p>

<pre><code>- (void)viewDidLoad 
</code></pre>

<p>{
    [super viewDidLoad];</p>

<pre><code>UIImage* tmpImage = nil;
tmpImage = [roomImage resizedImage:imageScrollView.frame.size interpolationQuality:0];
imageView = [[UIImageView alloc] initWithImage:tmpImage];
imageView.contentMode = UIViewContentModeScaleAspectFit;

imageScrollView.delegate = self;
imageScrollView.canCancelContentTouches = NO;
imageScrollView.minimumZoomScale = 0.25;
imageScrollView.maximumZoomScale = 3.00;


imageScrollView.clipsToBounds = YES;

[imageView sizeToFit];
[imageScrollView addSubview:imageView];

imageScrollView.contentSize = imageView.frame.size;
    imageScrollView.contentMode = UIViewContentModeScaleAspectFit;  
    imageScrollView.contentOffset = CGPointMake(imageScrollView.frame.size.width/2, imageScrollView.frame.size.height/2);
imageScrollView.autoresizesSubviews = YES;
imageScrollView.autoresizingMask =  UIViewAutoresizingFlexibleHeight |        UIViewAutoresizingFlexibleWidth   |  
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | 
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;


CGFloat f,x,y;

if(tmpImage.size.height &gt; tmpImage.size.width)
{
    f = (imageScrollView.frame.size.height/tmpImage.size.height);
}
else
{
    f = (imageScrollView.frame.size.width/tmpImage.size.width);
}

x = (imageScrollView.frame.size.width - tmpImage.size.width*f)/2;
y = (imageScrollView.frame.size.height - tmpImage.size.height*f)/2;

imageView.bounds = CGRectMake(x, y,tmpImage.size.width, tmpImage.size.height);
[imageView setNeedsDisplay];
[imageScrollView setZoomScale:f animated:YES];
[imageScrollView setNeedsDisplay];

jpgPath = nil;
[roomImage release];
roomImage = nil;
</code></pre>

<p>}</p>

<p>Hope any one can help me out..,</p>

<p>Thanks in advance..,</p>
