0

I am currently writting an ios5 app and call two functions (back) and (next) with buttons. I would like to call them with swipe gestures instead.

Would that be possible and how?

Thanks

1 Answers1

4

Use swipe gesture for both right direction (next button) and left direction (back button) For left direction:

UISwipeGestureRecognizer *swipeLeft =[[UISwipeGestureRecognizer alloc]
    initWithTarget:self action:@selector(didSwipeLeft:)];
swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;
swipeLeft.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:swipeLeft];
[swipeLeft release];

For right direction:

UISwipeGestureRecognizer *swipeRight =[[UISwipeGestureRecognizer alloc]
    initWithTarget:self action:@selector(didSwipeRight:)];
swipeRight .direction=UISwipeGestureRecognizerDirectionRight;
swipeRight .numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:swipeRight ];
[swipeRight release];

You handle them with events:

 -(void)didSwipeRight
 {
   //For right direction (next button)
 }

  -(void)didSwipeLeft
 {
   //For left direction (back button)
 }
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • thank you for the code. Would you please elaborate your answer and tell me how to integrate it with `Page Control`? and if I need to connect it with Storyboard. I have upvoted your answer :) – user1949873 May 15 '13 at 23:41