Skip to content

Instantly share code, notes, and snippets.

@evanlong
Created March 5, 2012 08:55
Show Gist options
  • Save evanlong/1977533 to your computer and use it in GitHub Desktop.
Save evanlong/1977533 to your computer and use it in GitHub Desktop.
Some gesture stuff
#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