Hello all,
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.
The requirement is "the image must facilitate 1/4th size for zoom out and 3 times the size for zoom in".
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)
Below is the code..,
- (void)viewDidLoad
{ [super viewDidLoad];
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 > 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;
}
Hope any one can help me out..,
Thanks in advance..,