IOS: UISwipeGestureRecognizer - ios

I have this code:
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(rightSwipeHandle:)];
[recognizer setNumberOfTouchesRequired:1];
[n16 addGestureRecognizer:recognizer];
[n17 addGestureRecognizer:recognizer];
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{
NSLog(#"SWIPE");
}
How can I know what view happens gesture? views are n16 and n17

I am not sure if you can register the same UIGestureRecognizer instance to different views, but if you could, I think UIGestureRecognizer.view property is what you are looking for.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UIGestureRecognizer
So, you should be able to do something like this. (again, I am not sure if you can attach different UIGestureRecognizer instance to different views...)
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{
if(gestureRecognizer.view == n16)
{
// specific operation to n16
}
else if(gestureRecognizer.view == n17)
{
// specific operation to n17
}
}

Like this:
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer {
NSLog(#"SWIPE");
UIView *vw = [gestureRecognizer view]; // this is the view that generated the
// gesture - either n16 or n17
}

Related

UISwipeGestureRecognizer UIGestureRecognizerStateChanged not called

I'm define two UISwipeGestureRecognizer in my application:
UISwipeGestureRecognizer *swipeLeftVolume = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeGestureVolume:)];
swipeLeftVolume.direction = UISwipeGestureRecognizerDirectionLeft;
[self.playerView addGestureRecognizer:swipeLeftVolume];
UISwipeGestureRecognizer *swipeRightVolume = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeGestureVolume:)];
swipeRightVolume.direction = UISwipeGestureRecognizerDirectionRight;
[self.playerView addGestureRecognizer:swipeRightVolume];
In the target method i have 3 states:
UIGestureRecognizerStateBegan
UIGestureRecognizerStateChanged
UIGestureRecognizerStateEnded
and i noticed that only the UIGestureRecognizerStateEnded is called.
Any idea what can be the problem? i want to recognize a swipe on specific UIView :
- (void)handleSwipeGestureVolume:(UISwipeGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
NSLog(#"Start");
} else if (sender.state == UIGestureRecognizerStateChanged) {
NSLog(#"Changed");
} else if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(#"Finish");
}
}
Seem like you are confused between UISwipeGestureRecognizer and UIPanGestureRecognizer.
UISwipeGestureRecognizer will generate UIGestureRecognizerStateEnded state only while UIPanGestureRecognizer has both 3 states you want.
If you need to receive both UIGestureRecognizerStateBegan, UIGestureRecognizerStateChanged, UIGestureRecognizerStateEnded, use UIPanGestureRecognizer instead.
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeGestureVolume:)];
[self.playerView addGestureRecognizer:panGesture];
Make sure you enable UserInteraction for self.playerView.
For any gesture recogniser, user interaction must be enabled to work. Without it none of the gestures will be triggered including touchBegan:, touchMove:, etc.
so you need to make [self.playerView setUserInteractionEnabled:TRUE];
And one more thing I would like to let you know that if you have implemented touchBegan:, touchMove:, etc. then the method will be triggered first for gesture rather than UIGestureRecognizer shilds.

how can check that which uiimageview is presently clicked?

I have three UIImageview. I set the action for UIImageview by using tapGesture. I want each UIImageview to have a different action. How can I check that which UIImageview is presently clicked?
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(singleTapping:)];
[singleTap setNumberOfTapsRequired:1];
[_imageOne addGestureRecognizer:singleTap];
[_imageTwo addGestureRecognizer:singleTap];
[_imageThree addGestureRecognizer:singleTap];
-(void)singleTapping:(UIGestureRecognizer *)recognizer {
}
You can detect using below code:
-(void)singleTapping:(UITapGestureRecognizer *) recognizer{
if (recognizer.view == _imageOne){
} else if (recognizer.view == _imageTwo) {
}else
{
}
}
A UIGestureRecognizer is to be used with a single view. There is this explicit information in the Apple documentation:
Gesture Recognizers Are Attached to a View
Every gesture recognizer is associated with one view. By contrast, a
view can have multiple gesture recognizers, because a single view
might respond to many different gestures. For a gesture recognizer to
recognize touches that occur in a particular view, you must attach the
gesture recognizer to that view.
Firstly, you can't attach same UITapGestureRecognizer to more than one view.
So, your code will not work and you have to create three UITapGestureRecognizer instances and have to attach it to views like below:
UITapGestureRecognizer *singleTapImg1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(singleTapping:)];
[singleTapImg1 setNumberOfTapsRequired:1];
UITapGestureRecognizer *singleTapImg2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(singleTapping:)];
[singleTapImg2 setNumberOfTapsRequired:1];
UITapGestureRecognizer *singleTapImg3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(singleTapping:)];
[singleTapImg3 setNumberOfTapsRequired:1];
[_imageOne addGestureRecognizer:singleTapImg1];
[_imageTwo addGestureRecognizer:singleTapImg2];
[_imageThree addGestureRecognizer:singleTapImg3];
Now, you can use below code to get, which imageview clicked and perform action according to that:
-(void)singleTapping:(UIGestureRecognizer *)recognizer {
if (recognizer.view == _imageOne){
//_imageOne tapped
}
else if (recognizer.view == _imageTwo) {
//_imageTwo tapped
}else{
//_imageThree tapped
}
}

how to add UITapGestureRecognizer to presentViewController and to view

I need to dismiss the presentViewController when click the outside the controller, I'm using the following code
UITapGestureRecognizer *tapBehindGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapBehindDetected:)];
[tapBehindGesture setNumberOfTapsRequired:1];
[tapBehindGesture setCancelsTouchesInView:NO];
[self.view.window addGestureRecognizer:tapBehindGesture];
- (void)tapBehindDetected:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded)
{
CGPoint location = [sender locationInView:nil]; //Passing nil gives us coordinates in the window
//Then we convert the tap's location into the local view's coordinate system, and test to see if it's in or outside. If outside, dismiss the view.
if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil])
{
// Remove the recognizer first so it's view.window is valid.
[self.view.window removeGestureRecognizer:sender];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
}
its working fine for me, but i had problem in another view. Inside the view controller I add UITapGestureRecognizer to vwHeaderview.
UITapGestureRecognizer *addNewContactsingleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap:)];
[vwHeaderview addGestureRecognizer:addNewContactsingleFingerTap];
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer
{
//Some code
}
If I click the vwHeaderview It call the "tapBehindDetected", I wont call "handleSingleTap".
If I comment above "tapBehindGesture" Its working fine. But I need both to work. any help
I add delegate to vwHeaderview and use following function & its working fine for me...
UITapGestureRecognizer *addNewContactsingleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap:)];
addNewContactsingleFingerTap.delegate = self;
[vwHeaderview addGestureRecognizer:addNewContactsingleFingerTap];
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}

Attach GestureRecogniser to multiple imageviews

Something strange I encountered today while attaching same gesture recogniser to multiple image views. It gets attached to only the last one, in other words, it can be attached to only one view!
I had to create multiple gesture recognisers to meet my requirements.
Following is what I have done. Am I doing correct? Is that's the only way to attach recognisers to the multiple imageviews?
Please note that I don't want to use UITableView or UIVIew and put all imageviews in it and attach gesture recogniser to only UITableView or UIVIew. I have all image scattered and I have to detect which image is being dragged. Thanks.
[imgView1 setUserInteractionEnabled:YES];
[imgView1 setMultipleTouchEnabled:YES];
[imgView2 setUserInteractionEnabled:YES];
[imgView2 setMultipleTouchEnabled:YES];
[imgView3 setUserInteractionEnabled:YES];
[imgView3 setMultipleTouchEnabled:YES];
[imgView4 setUserInteractionEnabled:YES];
[imgView4 setMultipleTouchEnabled:YES];
[imgView5 setUserInteractionEnabled:YES];
[imgView5 setMultipleTouchEnabled:YES];
[imgView6 setUserInteractionEnabled:YES];
[imgView6 setMultipleTouchEnabled:YES];
//Attach gesture recognizer to each imagviews
gestureRecognizer1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(gestureHandler:)];
gestureRecognizer1.delegate = self;
gestureRecognizer2 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(gestureHandler:)];
gestureRecognizer2.delegate = self;
gestureRecognizer3 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(gestureHandler:)];
gestureRecognizer3.delegate = self;
gestureRecognizer4 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(gestureHandler:)];
gestureRecognizer4.delegate = self;
gestureRecognizer5 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(gestureHandler:)];
gestureRecognizer5.delegate = self;
gestureRecognizer6 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(gestureHandler:)];
gestureRecognizer6.delegate = self;
[imgView1 addGestureRecognizer:gestureRecognizer1];
[imgView2 addGestureRecognizer:gestureRecognizer2];
[imgView3 addGestureRecognizer:gestureRecognizer3];
[imgView4 addGestureRecognizer:gestureRecognizer4];
[imgView5 addGestureRecognizer:gestureRecognizer5];
[imgView6 addGestureRecognizer:gestureRecognizer6];
Yes, one view per gesture recognizer. So if you want only one recognizer, put it on the superview, e.g.:
UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(gestureHandler:)];
[self.view addGestureRecognizer:gestureRecognizer];
And then, in your handler, you can:
- (void)handleLongPress:(UILongPressGestureRecognizer *)sender
{
CGPoint location = [sender locationInView:self.view];
if (sender.state == UIGestureRecognizerStateBegan)
{
for (UIView *view in self.view.subviews)
{
if ([view isKindOfClass:[UIImageView class]] && CGRectContainsPoint(view.frame, location))
{
UIImageView *image = (UIImageView *) view;
// ok, now you know which image you received your long press for
// do whatever you wanted on it at this point
return;
}
}
}
}
By the way, if you do that, you don't need to worry about enabling user interaction on the images, either.
Finally, you don't need to worry about specifying your gesture recognizer's delegate unless you're going to conform to UIGestureRecognizerDelegate, which this isn't. Also note that I'm using a local var for my recognizer because there's no reason to hang onto it.
Update:
While the above code works fine, perhaps even better would be a custom long press gesture recognizer that would fail if the long press didn't take place over an image (this way it's more likely to play well in case you have other gesture recognizers taking place in your view). So:
#import <UIKit/UIGestureRecognizerSubclass.h>
#interface ImageLongPressGestureRecognizer : UILongPressGestureRecognizer
#property (nonatomic, weak) UIImageView *imageview;
#end
#implementation ImageLongPressGestureRecognizer
#synthesize imageview = _imageview;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.imageview = nil;
[super touchesBegan:touches withEvent:event];
CGPoint location = [self locationInView:self.view];
for (UIView *view in self.view.subviews)
{
if ([view isKindOfClass:[UIImageView class]] && CGRectContainsPoint(view.frame, location))
{
self.imageview = (UIImageView *)view;
return;
}
}
self.state = UIGestureRecognizerStateFailed;
}
#end
then create your gesture recognizer accordingly, using this new subclass:
ImageLongPressGestureRecognizer *gestureRecognizer = [[ImageLongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongPress:)];
[self.view addGestureRecognizer:gestureRecognizer];
and then, as a nice little benefit of this subclassing, your main gesture recognizer is simplified, namely:
- (void)handleLongPress:(ImageLongPressGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan)
{
// you can now do whatever you want with sender.imageview, e.g. this makes it blink for you:
[UIView animateWithDuration:0.5
animations:^{
sender.imageview.alpha = 0.0;
} completion:^(BOOL finished){
[UIView animateWithDuration:0.5
animations:^{
sender.imageview.alpha = 1.0;
}
completion:nil];
}];
}
}
You can't attach a gesture recognizer to more than one object (as you discovered). One solution to what you are doing might be to subclass UIImageView and have setup code in that class so each view creates its recognizer, etc.
I guess, first of all, you should make an array of views and array of recognizers (mutable array, if needed) and then populate it. It will help you to use cycles to avoid code duplication.
As for multiple view with one recognizer - no, it's not possible, answered here.

Setting direction for UISwipeGestureRecognizer

I want to add simple swipe gesture recognition to my view based iPhone project. Gestures in all directions (right, down, left, up) should be recognized.
It is stated in the docs for UISwipeGestureRecognizer:
You may specify multiple directions by specifying multiple UISwipeGestureRecognizerDirection constants using bitwise-OR operands. The default direction is UISwipeGestureRecognizerDirectionRight.
However for me it doesn't work. When all four directions are OR'ed only left and right swipes are recognized.
- (void)viewDidLoad {
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
[super viewDidLoad];
}
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(#"Swipe received.");
}
I fixed this with adding four recognizers to the view but I'm curious to know why didn't it work as advertised in docs?
- (void)viewDidLoad {
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
[super viewDidLoad];
}
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(#"Swipe received.");
}
Seems like there is a bug. You can specify the allowed direction(s) as you did. But when you try to access the actual direction that triggered the swipe in the action selector method you still get the bit mask you originally set (for the allowed directions).
This means that checks for the actual direction will always fail when more than 1 direction is allowed.
You can see it for yourself quite easily when you output the value of 'direction' in the selector method (ie -(void)scrollViewSwiped:(UISwipeGestureRecognizer *)recognizer).
Filed a bug report (#8276386) to Apple.
[Update] I got an answer from Apple saying that the behavior works as was intended.
So for example in a table view you can swipe left or right in a table view cell to trigger 'delete' (this would have directions of the swipe gesture set to left and right)
This means that the original workaround is the way it's supposed to be used. The direction property can only be used to get the gestures recognized correctly, but not in the method performed on a successful recognition to compare for the actual direction that triggered the recognition.
I noticed that left/right and up/down gestures work together in pairs, so you only need to specify two gesture recognizers. And the docs do seem to be wrong.
Well that sucks, I solved the problem by adding 2 gestures like Lars mentioned and that worked perfectly...
1) Left/Right
2) Up/Down
UISwipeGestureRecognizer *swipeLeftRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
[swipeLeftRight setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft )];
[self.view addGestureRecognizer:swipeLeftRight];
UISwipeGestureRecognizer *swipeUpDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
[swipeUpDown setDirection:(UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown )];
[self.view addGestureRecognizer:swipeUpDown];
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(didSwipe:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(didSwipe:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
Now this is the didSwipe function
- (void) didSwipe:(UISwipeGestureRecognizer *)recognizer{
if([recognizer direction] == UISwipeGestureRecognizerDirectionLeft){
//Swipe from right to left
//Do your functions here
}else{
//Swipe from left to right
//Do your functions here
}
}
If your using Xcode 4.2 you can add Gesture Recognizers # the storyboard and then link the GUI Gesture Recognizers to IBActions.
You can find the Gesture Recognizers in the Object Library of the Utility Pane (The bottom of the Right pane).
Then its just a matter of Control-dragging to the appropriate action.
If you want it to detect all four directions, you'll need to create four instances, as you did in your work-around.
Here's Why:
The same instance of UISwipeGestureRecognizer that you create is the instance that gets passed to the selector as sender. So if you set it to recognize all four directions, it will return true for sgr.direction == xxx where xxx is any one of the four directions.
Here's an alternative work-around that involves less code (assumes ARC use):
for(int d = UISwipeGestureRecognizerDirectionRight; d <= UISwipeGestureRecognizerDirectionDown; d = d*2) {
UISwipeGestureRecognizer *sgr = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
sgr.direction = d;
[self.view addGestureRecognizer:sgr];
}
Swift 2.1
I had to use the following
for var x in [
UISwipeGestureRecognizerDirection.Left,
UISwipeGestureRecognizerDirection.Right,
UISwipeGestureRecognizerDirection.Up,
UISwipeGestureRecognizerDirection.Down
] {
let r = UISwipeGestureRecognizer(target: self, action: "swipe:")
r.direction = x
self.view.addGestureRecognizer(r)
}
Here is a code sample for UISwipeGestureRecognizer usage. Note comments.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//add gesture recognizer. The 'direction' property of UISwipeGestureRecognizer only sets the allowable directions. It does not return to the user the direction that was actaully swiped. Must set up separate gesture recognizers to handle the specific directions for which I want an outcome.
UISwipeGestureRecognizer *gestureRight;
UISwipeGestureRecognizer *gestureLeft;
gestureRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeRight:)];//direction is set by default.
gestureLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeLeft:)];//need to set direction.
[gestureLeft setDirection:(UISwipeGestureRecognizerDirectionLeft)];
//[gesture setNumberOfTouchesRequired:1];//default is 1
[[self view] addGestureRecognizer:gestureRight];//this gets things rolling.
[[self view] addGestureRecognizer:gestureLeft];//this gets things rolling.
}
swipeRight and swipeLeft are methods that you use to perform specific activities based on left or right swiping. For example:
- (void)swipeRight:(UISwipeGestureRecognizer *)gesture
{
NSLog(#"Right Swipe received.");//Lets you know this method was called by gesture recognizer.
NSLog(#"Direction is: %i", gesture.direction);//Lets you know the numeric value of the gesture direction for confirmation (1=right).
//only interested in gesture if gesture state == changed or ended (From Paul Hegarty # standford U
if ((gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
//do something for a right swipe gesture.
}
}
UISwipeGestureRecognizer *Updown=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(handleGestureNext:)];
Updown.delegate=self;
[Updown setDirection:UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp];
[overLayView addGestureRecognizer:Updown];
UISwipeGestureRecognizer *LeftRight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(handleGestureNext:)];
LeftRight.delegate=self;
[LeftRight setDirection:UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight];
[overLayView addGestureRecognizer:LeftRight];
overLayView.userInteractionEnabled=NO;
-(void)handleGestureNext:(UISwipeGestureRecognizer *)recognizer
{
NSLog(#"Swipe Recevied");
//Left
//Right
//Top
//Bottom
}
hmm, strange, it works perfect for me, I do exactly same thing
think you should try look at
UIGestureRecognizerDelegate method
- (BOOL)gestureRecognizerShouldBegin:(UISwipeGestureRecognizer *)gestureRecognizer {
// also try to look what's wrong with gesture
NSLog(#"should began gesture %#", gestureRecognizer);
return YES;
}
in logs you must see something like:
should began gesture ; target= <(action=actionForUpDownSwipeGestureRecognizer:, target=)>; direction = up,down,left,right>
use this, it should be the bit operation
gesture.direction & UISwipeGestureRecognizerDirectionUp ||
gesture.direction & UISwipeGestureRecognizerDirectionDown
This was driving me crazy. I finally figured out a reliable way to have multiple swipeGestureRecognizers.
It appears there is a bug in iOS if the name of your "action" selector is the same across multiple swipeGestureRecognizers. If you just name them differently, e.g. handleLeftSwipeFrom and handleRightSwipeFrom, everything works.
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleLeftSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleRightSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];

Resources