switching view controllers using swipe gestures

Julio Savala Lopez picture Julio Savala Lopez · Jun 26, 2013 · Viewed 11.3k times · Source

Okay so here is the problem I'm running into:

I am attempting to switch from one viewController that I named MenuViewController which contains my menu (obviously). I have a separate viewController named ViewController that contains my mapView. I would like to be able to double finger swipe left from my MenuViewController over to my mapView.

I'm not exactly sure where to start.

Also, I am using xib files, and not the storyboard. Running iOS 6.

Answer

Girish picture Girish · Jun 26, 2013
UISwipeGestureRecognizer *swipeLeftGesture=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
[self.view addGestureRecognizer:swipeLeftGesture];
swipeLeftGesture.direction=UISwipeGestureRecognizerDirectionLeft;

-(void)handleSwipeGesture:(UIGestureRecognizer *) sender
{
    NSUInteger touches = sender.numberOfTouches;
    if (touches == 2)
    {
        if (sender.state == UIGestureRecognizerStateEnded)
        { 
            //Add view controller here    
        }
    }  
}