Permalink
Browse files

Configure gesture number of touches

Allow define how many fingers can be used to move views.
  • Loading branch information...
1 parent f83007a commit fb0fecde3852f0bd27b1c84cd4ffdbfe7f5cc537 @krzyzanowskim krzyzanowskim committed Feb 24, 2012
Showing with 36 additions and 12 deletions.
  1. +5 −0 PSStackedView/PSStackedViewController.h
  2. +31 −12 PSStackedView/PSStackedViewController.m
@@ -133,6 +133,9 @@ enum {
/// corner radius
@property(nonatomic, assign) CGFloat cornerRadius;
+///number of touches
+@property(nonatomic, assign) NSUInteger numberOfTouches;
+
/// left inset thats always visible. Defaults to 60.
@property(nonatomic, assign) NSUInteger leftInset;
/// animate setting of the left inset that is always visible
@@ -143,6 +146,8 @@ enum {
/// animate setting of large left inset
- (void)setLargeLeftInset:(NSUInteger)largeLeftInset animated:(BOOL)animated;
+
+
// compatibility with UINavigationBar -- returns nil
#ifdef ALLOW_SWIZZLING_NAVIGATIONCONTROLLER
@property(nonatomic, assign) UINavigationBar *navigationBar;
@@ -68,6 +68,7 @@ @implementation PSStackedViewController
@synthesize defaultShadowWidth = defaultShadowWidth_;
@synthesize defaultShadowAlpha = defaultShadowAlpha_;
@synthesize cornerRadius = cornerRadius_;
+@synthesize numberOfTouches = numberOfTouches_;
@dynamic firstVisibleIndex;
#ifdef ALLOW_SWIZZLING_NAVIGATIONCONTROLLER
@@ -77,6 +78,26 @@ @implementation PSStackedViewController
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - NSObject
+- (void)configureGestureRecognizer
+{
+ [self.view removeGestureRecognizer:self.panRecognizer];
+
+ // add a gesture recognizer to detect dragging to the guest controllers
+ UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanFrom:)];
+ if (numberOfTouches_ > 0)
+ {
+ [panRecognizer setMinimumNumberOfTouches:numberOfTouches_];
+ } else {
+ [panRecognizer setMaximumNumberOfTouches:1];
+ }
+ [panRecognizer setDelaysTouchesBegan:NO];
+ [panRecognizer setDelaysTouchesEnded:YES];
+ [panRecognizer setCancelsTouchesInView:YES];
+ panRecognizer.delegate = self;
+ [self.view addGestureRecognizer:panRecognizer];
+ self.panRecognizer = panRecognizer;
+}
+
- (id)initWithRootViewController:(UIViewController *)rootViewController; {
if ((self = [super init])) {
rootViewController_ = rootViewController;
@@ -88,24 +109,16 @@ - (id)initWithRootViewController:(UIViewController *)rootViewController; {
leftInset_ = 60;
largeLeftInset_ = 200;
- // add a gesture recognizer to detect dragging to the guest controllers
- UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanFrom:)];
- [panRecognizer setMaximumNumberOfTouches:1];
- [panRecognizer setDelaysTouchesBegan:NO];
- [panRecognizer setDelaysTouchesEnded:YES];
- [panRecognizer setCancelsTouchesInView:YES];
- panRecognizer.delegate = self;
- [self.view addGestureRecognizer:panRecognizer];
- self.panRecognizer = panRecognizer;
+ [self configureGestureRecognizer];
+
enableBounces_ = YES;
enableShadows_ = YES;
enableDraggingPastInsets_ = YES;
enableScalingFadeInOut_ = YES;
defaultShadowWidth_ = 60.0f;
defaultShadowAlpha_ = 0.2f;
cornerRadius_ = 6.0f;
-
-
+
#ifdef ALLOW_SWIZZLING_NAVIGATIONCONTROLLER
PSSVLog("Swizzling UIViewController.navigationController");
Method origMethod = class_getInstanceMethod([UIViewController class], @selector(navigationController));
@@ -798,7 +811,7 @@ - (void)moveStackWithOffset:(NSInteger)offset animated:(BOOL)animated userDraggi
} completion:nil];
}
-- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer {
+- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer {
CGPoint translatedPoint = [recognizer translationInView:self.view];
UIGestureRecognizerState state = recognizer.state;
@@ -1359,6 +1372,12 @@ - (NSUInteger)expandStack:(NSInteger)steps animated:(BOOL)animated; { // (---> d
return steps;
}
+- (void)setNumberOfTouches:(NSUInteger)numberOfTouches
+{
+ numberOfTouches_ = numberOfTouches;
+ [self configureGestureRecognizer];
+}
+
- (void)setLeftInset:(NSUInteger)leftInset {
[self setLeftInset:leftInset animated:NO];
}

0 comments on commit fb0fecd

Please sign in to comment.