Permalink
Browse files

Improve feel and fluidity of gesture recognition

  • Loading branch information...
ole committed Jan 25, 2012
1 parent 30141a0 commit e23e300087883f6f95b5481d3eb05add7d86a8fd
Showing with 18 additions and 7 deletions.
  1. +1 −1 GestureRecognizers/ViewController.h
  2. +17 −6 GestureRecognizers/ViewController.m
@@ -8,7 +8,7 @@
#import <UIKit/UIKit.h>
-@interface ViewController : UIViewController
+@interface ViewController : UIViewController <UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@@ -23,20 +23,23 @@ - (void)viewDidLoad
{
[super viewDidLoad];
- self.imageView.userInteractionEnabled = YES;
-
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
- [self.imageView addGestureRecognizer:panRecognizer];
+ [self.view addGestureRecognizer:panRecognizer];
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchDetected:)];
- [self.imageView addGestureRecognizer:pinchRecognizer];
+ [self.view addGestureRecognizer:pinchRecognizer];
UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationDetected:)];
- [self.imageView addGestureRecognizer:rotationRecognizer];
+ [self.view addGestureRecognizer:rotationRecognizer];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
tapRecognizer.numberOfTapsRequired = 2;
- [self.imageView addGestureRecognizer:tapRecognizer];
+ [self.view addGestureRecognizer:tapRecognizer];
+
+ panRecognizer.delegate = self;
+ pinchRecognizer.delegate = self;
+ rotationRecognizer.delegate = self;
+ // We don't need a delegate for the tapRecognizer
}
- (void)viewDidUnload
@@ -112,4 +115,12 @@ - (void)tapDetected:(UITapGestureRecognizer *)tapRecognizer
}];
}
+
+#pragma mark - UIGestureRecognizerDelegate
+
+- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
+{
+ return YES;
+}
+
@end

0 comments on commit e23e300

Please sign in to comment.