2

Im trying to add Swipe Gesture Recognizer to my app so I can swipe to either left or right to get to another view controller. I drag the object to the viewcontroller that I want, link it up so when swiping right it should take me to another viewcontroller. I run the simulator but the swipe feature doesn't take me to the other view.

When creating a new project, just adding 3 viewcontroller and swipe gestures I can swipe in the simulator and it takes me to another viewcontroller. But doing the exact same thing in my current app doesn't do anything.

Any ideas? I've tried to play around with enable/disable state but still get nothing

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2780856
  • 49
  • 2
  • 6
  • What are the differences? What is in the view that doesn't work? – Wain Dec 15 '13 at 16:19
  • show the code you are trying to implement. also read : http://useyourloaf.com/blog/2011/11/24/creating-gesture-recognizers-with-interface-builder.html – staticVoidMan Dec 15 '13 at 16:46

3 Answers3

6

If you are comfortable with writing codes then please try this.

UISwipeGestureRecognizer *left = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(PerformAction:)];
left.direction = UISwipeGestureRecognizerDirectionLeft ;
[self.view addGestureRecognizer:left];

UISwipeGestureRecognizer *right = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(PerformAction:)];
right.direction = UISwipeGestureRecognizerDirectionRight ;
    [self.view addGestureRecognizer:right];

Now perform action like this :

-(void)PerformAction:(UISwipeGestureRecognizer *)sender {
    if(sender.direction == UISwipeGestureRecognizerDirectionRight) {
        NSLog(@"RIGHT GESTURE");
        // Perform your code here
    }

    if(sender.direction == UISwipeGestureRecognizerDirectionLeft) {
       NSLog(@"LEFT GESTURE");
       // Perform your code here
    }    
}

If you want to perform this on each viewcontroller then you have to device an intelligent logic to perform specific tasks on your left swipe & right swipe, based on your current viewcontroller.

Hope that helps.

Balram Tiwari
  • 5,657
  • 2
  • 23
  • 41
2

sometimes when recognizers overlap (like when you have a scrollView with a swipe recognizer) it can cause the touches to be cancelled.. try making sure nothing is interrupting your recognizer.

eiran
  • 1,378
  • 15
  • 16
0

I had the same problem and found some possible solutions:

  • Maybe you need to make your view userInteractionEnabled true:
    override func viewDidLoad() {
       self.view.isUserInteractionEnabled = true
       // configure your gestures ...
    }
  • Maybe one of your viewControllers has a TableView which is overlapping with your UISwipeGestureRecognizer, in that case you can implement UIGestureRecognizerDelegate, found in this answer.
rusito23
  • 995
  • 8
  • 20