Trying to zoom in / out an imageView.
i’ve managed that successfully so now i’m trying to place some buttons on the view and when button tapped to zoom on that area.
How can i implement that?
here is my code so far
-(void)zoomHere:(UIButton *)sender{
NSLog(@"zoom in");
//[self performSelector:@selector()
// withObject:nil
// afterDelay:1.6f];
CGAffineTransform transformer = CGAffineTransformScale(imageView.transform, 1.05, 1.05);
if (transformer.a < 5) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.2];
imageView.transform = transformer;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
}
and the view did load
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *buttonView = [[UIView alloc]initWithFrame:CGRectMake(00.0, 20.0, 768, 1004.0)];
zoomHere = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[zoomHere addTarget:self
action:@selector(zoomHere:)
forControlEvents:UIControlEventTouchDown];
[zoomHere setTitle:@"ZoomIN" forState:UIControlStateNormal];
zoomHere.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[buttonView addSubview:zoomHere];
buttonView.multipleTouchEnabled = YES;
[self.view addSubview:buttonView];
}
It still zoom in but not on that area where the button sits on screen!
if you want to use scale transform, you probably should use translate transform as well
like this:
this is how you know the position of button on your image view:
so if you know button’s coordinates and your current scale then you can calculate new translate transform
But as for me, i would rather use scroll view to zoom in and zoom out that image view. You can have nice bouncing animations and zooming animations, also you can have pan and pinch, but of cource it is up to you.