Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

switching view controllers using swipe gestures

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.

like image 484
Julio Savala Lopez Avatar asked Jun 26 '13 06:06

Julio Savala Lopez


People also ask

How do I switch between view controllers?

Right-click the control or object in your current view controller. Drag the cursor to the view controller you want to present. Select the kind of segue you want from the list that Xcode provides.

What is swipe gesture?

One of the most common gestures you will use on your smartphone or tablet is a swipe. That's where you place your finger on the screen and slide it across the surface. In most instances, the item under your finger will move.

What is swipe gesture on iPhone?

Swipe right or left along the bottom edge of the screen to quickly switch between open apps. See Switch between open apps on iPhone.

How do you use swipe gestures in Swift 4?

A swipe gesture recognizer detects swipes in one of four directions, up , down , left , and right . We set the direction property of the swipe gesture recognizer to down . If the user swipes from the top of the blue view to the bottom of the blue view, the swipe gesture recognizer invokes the didSwipe(_:)


2 Answers

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    
        }
    }  
}
like image 91
Girish Avatar answered Sep 24 '22 06:09

Girish


once go through this,

UISwipeGestureRecognizer  *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleleftSwipe:)];
swipeLeft.numberOfTouchesRequired = 1;//give required num of touches here ..
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.delegate = (id)self;
[self. view addGestureRecognizer:swipeLeft];

UISwipeGestureRecognizer  *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handlerightSwipe:)];
swipeRight.numberOfTouchesRequired = 1;//give required num of touches here ..
swipeRight.delegate = (id)self;
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];

now define swipe methods like below:

 -(void)handleleftSwipe:(UISwipeGestureRecognizer *)recognizer{
//Do ur code for Push/pop..
  }
-(void)handlerightSwipe:(UISwipeGestureRecognizer *)recognizer{
 //Do ur code for Push/pop..
  }

Hope it helps you...

like image 30
iSpark Avatar answered Sep 21 '22 06:09

iSpark