Skip to content

Instantly share code, notes, and snippets.

@lilyball
Created August 24, 2010 01:05
Show Gist options
  • Save lilyball/546690 to your computer and use it in GitHub Desktop.
Save lilyball/546690 to your computer and use it in GitHub Desktop.
#import <UIKit/UIKit.h>
@interface ScaleTestViewController : UIViewController
@property (nonatomic, retain) IBOutlet UIView *scaleView;
@end
#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