Created
August 24, 2010 01:05
-
-
Save lilyball/546690 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface ScaleTestViewController : UIViewController | |
@property (nonatomic, retain) IBOutlet UIView *scaleView; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ScaleTestViewController.h" | |
@implementation ScaleTestViewController | |
@synthesize scaleView=_scaleView; | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(234, 362, 300, 300)] autorelease]; | |
view.backgroundColor = [UIColor greenColor]; | |
[self.view addSubview:view]; | |
self.scaleView = view; | |
UIPinchGestureRecognizer *recog = [[[UIPinchGestureRecognizer alloc] initWithTarget:self | |
action:@selector(gestureRecognizerChanged:)] autorelease]; | |
[self.scaleView addGestureRecognizer:recog]; | |
} | |
- (void)gestureRecognizerChanged:(UIPinchGestureRecognizer *)recog { | |
if (recog.state == UIGestureRecognizerStateBegan) { | |
recog.scale = recog.view.transform.a; | |
} else { | |
CGFloat scale = MAX(recog.scale, 1.0f); | |
recog.view.transform = CGAffineTransformMakeScale(scale, scale); | |
} | |
} | |
// Override to allow orientations other than the default portrait orientation. | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | |
return YES; | |
} | |
- (void)didReceiveMemoryWarning { | |
// Releases the view if it doesn't have a superview. | |
[super didReceiveMemoryWarning]; | |
// Release any cached data, images, etc that aren't in use. | |
} | |
- (void)viewDidUnload { | |
self.scaleView = nil; | |
} | |
- (void)dealloc { | |
[_scaleView release]; | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment