0

How can I detect which way the user swiped my page view controller? This should be simple but I cannot seem to find a reliable way to do this! Can anyone help me with a simple answer to tell which way the user has swiped a page!

Thanks.

  • I guess this answer is what you need http://stackoverflow.com/a/8813202/599900 – varu May 11 '15 at 07:47
  • 1
    See [this answer](http://stackoverflow.com/a/27934069/3985749) to a similar question. – pbasdf May 11 '15 at 07:54
  • Why you need that? Just provide left and right view controllers. – Cy-4AH May 11 '15 at 08:33
  • I have five view controllers that loop because I am going to display about 1000 different pieces of data from an array over those five view controllers that loop, and it would be impractical to have 1000 different view controllers, so therefor I need to detect the swipe direction for an int that will determine the index of my array that I will call from. – Cool Kat Studios May 11 '15 at 09:28

2 Answers2

0

There could be functions like first touch and last touch. So you can understand the direction by simple aritmetical operations. Then swipe won't be too different initial and ending point are key elements for understanding the direction as well.

I assume you have already checked it but may missed little details.

Here - Apple Developers Site

coner
  • 270
  • 7
  • 21
-2

Left swipe used this:

UISwipeGestureRecognizer* leftSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];

leftSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;

[self.tableView addGestureRecognizer:leftSwipeRecognizer];

Right swipe used this:

UISwipeGestureRecognizer* rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];

rightSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;

[self.tableView addGestureRecognizer:rightSwipeRecognizer];
Venkadesh
  • 5
  • 5
  • 1
    Do you realise the OP is asking about a UIPageViewController and you are answering with some copy/paste UITableView code, right? Unless you provide a specific way of attaching those gesture recognizers to the underlying UIPageView then your answer is not only incomplete but wrong. BTW, attaching GR to a UIPageView will pretty much give you more headaches than maintaining an Index. – mradzinski Sep 21 '16 at 22:11