Created
March 5, 2012 08:55
-
-
Save evanlong/1977533 to your computer and use it in GitHub Desktop.
Some gesture stuff
This file contains hidden or 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 "LWViewController.h" | |
@interface LWViewController () | |
@property (nonatomic, retain) UIView *outerSubview; | |
@property (nonatomic, retain) UIView *innerSubview; | |
@end | |
@implementation LWViewController | |
@synthesize outerSubview = _outerSubview; | |
@synthesize innerSubview = _innerSubview; | |
- (void)dealloc { | |
[_outerSubview release]; | |
[_innerSubview release]; | |
[super dealloc]; | |
} | |
- (void)viewDidUnload { | |
[_outerSubview release]; | |
[_innerSubview release]; | |
[super viewDidUnload]; | |
} | |
- (void)loadView { | |
CGRect frame = [UIScreen mainScreen].bounds; | |
self.view = [[[UIView alloc] initWithFrame:frame] autorelease]; | |
self.outerSubview = [[[UIView alloc] initWithFrame:frame] autorelease]; | |
self.outerSubview.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | |
self.outerSubview.backgroundColor = [UIColor grayColor]; | |
[self.view addSubview:self.outerSubview]; | |
CGRect subViewFrame = CGRectInset(frame, 75.0f, 75.0f); | |
self.innerSubview = [[[UIView alloc] initWithFrame:subViewFrame] autorelease]; | |
self.innerSubview.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | |
self.innerSubview.backgroundColor = [UIColor blueColor]; | |
[self.view addSubview:self.innerSubview]; | |
UIPanGestureRecognizer *panGesture = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_panOuter:)] autorelease]; | |
[self.outerSubview addGestureRecognizer:panGesture]; | |
panGesture = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_panInner:)] autorelease]; | |
[self.innerSubview addGestureRecognizer:panGesture]; | |
} | |
// Handlers for the gestures. So when "inside" the self.innerSubview from either gesture start handling the | |
// gesture with respect to the self.innerSubview | |
- (void)_panOuter:(UIPanGestureRecognizer *)gesture { | |
CGPoint p = [gesture locationInView:self.innerSubview]; | |
NSString *insideOutside = ([self.innerSubview pointInside:p withEvent:nil]) ? @"inside" : @"outside"; | |
NSLog(@"panOuter (%@): %@", insideOutside, NSStringFromCGPoint(p)); | |
} | |
- (void)_panInner:(UIPanGestureRecognizer *)gesture { | |
CGPoint p = [gesture locationInView:self.innerSubview]; | |
NSString *insideOutside = ([self.innerSubview pointInside:p withEvent:nil]) ? @"inside" : @"outside"; | |
NSLog(@"panInner (%@): %@", insideOutside, NSStringFromCGPoint(p)); | |
} | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | |
return YES; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment