Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
Improve feel and fluidity of gesture recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
ole committed Jan 25, 2012
1 parent 30141a0 commit e23e300
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion GestureRecognizers/ViewController.h
Expand Up @@ -8,7 +8,7 @@


#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>


@interface ViewController : UIViewController @interface ViewController : UIViewController <UIGestureRecognizerDelegate>


@property (weak, nonatomic) IBOutlet UIImageView *imageView; @property (weak, nonatomic) IBOutlet UIImageView *imageView;


Expand Down
23 changes: 17 additions & 6 deletions GestureRecognizers/ViewController.m
Expand Up @@ -23,20 +23,23 @@ - (void)viewDidLoad
{ {
[super viewDidLoad]; [super viewDidLoad];


self.imageView.userInteractionEnabled = YES;

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)]; 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:)]; 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:)]; 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:)]; UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
tapRecognizer.numberOfTapsRequired = 2; 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 - (void)viewDidUnload
Expand Down Expand Up @@ -112,4 +115,12 @@ - (void)tapDetected:(UITapGestureRecognizer *)tapRecognizer
}]; }];
} }



#pragma mark - UIGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

@end @end

0 comments on commit e23e300

Please sign in to comment.