Consider this as a draft from which to inhale:
//.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end //.m #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UIView *v1; @property (nonatomic, strong) UIView *v2; @property (nonatomic, strong) UIView *v3; @property (nonatomic, strong) UIView *v4; @end @implementation ViewController @synthesize v1 = _v1; @synthesize v2 = _v2; @synthesize v3 = _v3; @synthesize v4 = _v4; - (void)viewDidLoad { [super viewDidLoad]; _v1 = [[UIView alloc] initWithFrame:self.view.bounds]; _v2 = [[UIView alloc] initWithFrame:self.view.bounds]; _v3 = [[UIView alloc] initWithFrame:self.view.bounds]; _v4 = [[UIView alloc] initWithFrame:self.view.bounds]; [_v1 setBackgroundColor:[UIColor redColor]]; [_v2 setBackgroundColor:[UIColor yellowColor]]; [_v3 setBackgroundColor:[UIColor blueColor]]; [_v4 setBackgroundColor:[UIColor greenColor]]; _v1.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.)); _v1.frame = CGRectMake(10., 10., _v1.frame.size.width, _v1.frame.size.height); _v2.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.)); _v2.frame = CGRectMake(170., 10., _v2.frame.size.width, _v2.frame.size.height); _v3.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.)); _v3.frame = CGRectMake(10., 240., _v3.frame.size.width, _v3.frame.size.height); _v4.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.)); _v4.frame = CGRectMake(170., 240., _v4.frame.size.width, _v4.frame.size.height); _v1.tag = 1; _v2.tag = 2; _v3.tag = 3; _v4.tag = 4; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomAction:)]; [tap setNumberOfTapsRequired:1]; [_v1 addGestureRecognizer:tap]; [tap release]; tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomAction:)]; [tap setNumberOfTapsRequired:1]; [_v2 addGestureRecognizer:tap]; [tap release]; tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomAction:)]; [tap setNumberOfTapsRequired:1]; [_v3 addGestureRecognizer:tap]; [tap release]; tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomAction:)]; [tap setNumberOfTapsRequired:1]; [_v4 addGestureRecognizer:tap]; [tap release]; [self.view addSubview:_v1]; [self.view addSubview:_v2]; [self.view addSubview:_v3]; [self.view addSubview:_v4]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [btn setFrame:CGRectMake(10, 10, 100, 30)]; [btn setTitle:@"Close" forState:UIControlStateNormal]; btn.tag = 1; [btn addTarget:self action:@selector(zoomReverse:) forControlEvents:UIControlEventTouchUpInside]; [_v1 addSubview:btn]; btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [btn setFrame:CGRectMake(10, 10, 100, 30)]; [btn setTitle:@"Close" forState:UIControlStateNormal]; btn.tag = 2; [btn addTarget:self action:@selector(zoomReverse:) forControlEvents:UIControlEventTouchUpInside]; [_v2 addSubview:btn]; btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [btn setFrame:CGRectMake(10, 10, 100, 30)]; [btn setTitle:@"Close" forState:UIControlStateNormal]; btn.tag = 3; [btn addTarget:self action:@selector(zoomReverse:) forControlEvents:UIControlEventTouchUpInside]; [_v3 addSubview:btn]; btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [btn setFrame:CGRectMake(10, 10, 100, 30)]; [btn setTitle:@"Close" forState:UIControlStateNormal]; btn.tag = 4; [btn addTarget:self action:@selector(zoomReverse:) forControlEvents:UIControlEventTouchUpInside]; [_v4 addSubview:btn]; } - (void)zoomReverse:(UIButton *)sender { UITapGestureRecognizer *tap = nil; switch (sender.tag) { case 1: [self.view bringSubviewToFront:_v1]; tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomAction:)]; [tap setNumberOfTapsRequired:1]; [_v1 addGestureRecognizer:tap]; [tap release]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; _v1.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.)); _v1.frame = CGRectMake(10., 10., _v1.frame.size.width, _v1.frame.size.height); [UIView commitAnimations]; break; case 2: [self.view bringSubviewToFront:_v2]; tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomAction:)]; [tap setNumberOfTapsRequired:1]; [_v2 addGestureRecognizer:tap]; [tap release]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; _v2.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.)); _v2.frame = CGRectMake(170., 10., _v2.frame.size.width, _v2.frame.size.height); [UIView commitAnimations]; break; case 3: [self.view bringSubviewToFront:_v3]; tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomAction:)]; [tap setNumberOfTapsRequired:1]; [_v3 addGestureRecognizer:tap]; [tap release]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; _v3.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.)); _v3.frame = CGRectMake(10., 240., _v3.frame.size.width, _v3.frame.size.height); [UIView commitAnimations]; break; case 4: [self.view bringSubviewToFront:_v4]; tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zoomAction:)]; [tap setNumberOfTapsRequired:1]; [_v4 addGestureRecognizer:tap]; [tap release]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; _v4.transform = CGAffineTransformMakeScale(1/(320./140.), 1/(460./210.)); _v4.frame = CGRectMake(170., 240., _v4.frame.size.width, _v4.frame.size.height); [UIView commitAnimations]; break; default: break; } } - (void)zoomAction:(UITapGestureRecognizer *)sender { switch (sender.view.tag) { case 1: [self.view bringSubviewToFront:_v1]; [_v1 removeGestureRecognizer:[_v1.gestureRecognizers objectAtIndex:0]]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; _v1.transform = CGAffineTransformIdentity; _v1.frame = CGRectMake(0., 0., _v1.frame.size.width, _v1.frame.size.height); [UIView commitAnimations]; break; case 2: [self.view bringSubviewToFront:_v2]; [_v2 removeGestureRecognizer:[_v2.gestureRecognizers objectAtIndex:0]]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; _v2.transform = CGAffineTransformIdentity; _v2.frame = CGRectMake(0., 0., _v2.frame.size.width, _v2.frame.size.height); [UIView commitAnimations]; break; case 3: [self.view bringSubviewToFront:_v3]; [_v3 removeGestureRecognizer:[_v3.gestureRecognizers objectAtIndex:0]]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; _v3.transform = CGAffineTransformIdentity; _v3.frame = CGRectMake(0., 0., _v3.frame.size.width, _v3.frame.size.height); [UIView commitAnimations]; break; case 4: [self.view bringSubviewToFront:_v4]; [_v4 removeGestureRecognizer:[_v4.gestureRecognizers objectAtIndex:0]]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; _v4.transform = CGAffineTransformIdentity; _v4.frame = CGRectMake(0., 0., _v4.frame.size.width, _v4.frame.size.height); [UIView commitAnimations]; break; default: break; } } - (void)viewDidUnload { [super viewDidUnload]; [self setV1:nil]; [self setV2:nil]; [self setV3:nil]; [self setV4:nil]; } @end
Hope this helps.