Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle 1 to 3 fingers swipe gesture in iOS

I use the following code to handle 1 finger swipe in my code:

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleViewsSwipe:)];
    [swipe setDirection:UISwipeGestureRecognizerDirectionLeft];
    [swipe setDelaysTouchesBegan:YES];
    [[self view] addGestureRecognizer:swipe];

I know i can add the following line to make it handle 2 fingers swipe:

 [swipe setNumberOfTouchesRequired:2];

However when I add the above code 1 finger swipe is no longer detected since the number of touches required is now 2. What can I do to make my code work for 1, 2 or 3 fingers swipe?

I tried using the following code but this doesn't do what I want to do.

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleViewsSwipe:)];
    [panRecognizer setMinimumNumberOfTouches:1];
    [panRecognizer setMaximumNumberOfTouches:3];
    [panRecognizer setDelaysTouchesBegan:YES];
    [[self view] addGestureRecognizer:panRecognizer];
    [panRecognizer release];

Thank you.

like image 738
atbebtg Avatar asked Jan 29 '12 05:01

atbebtg


People also ask

How do you make a swipe gesture in IOS?

We can use the createSwipeGestureRecognizer(for:) method in the view controller's viewDidLoad() method to create a swipe gesture recognizer for each direction. We pass the result of createSwipeGestureRecognizer(for:) to the addGestureRecognizer(_:) method.

What does a three finger tap do on iPhone?

Use gestures to control VoiceOver Three-finger double tap. If both VoiceOver and Zoom are enabled, use the three-finger triple-tap gesture. (When the screen curtain is on, the screen contents are active even though the display is turned off.)

How do you turn off the three finger gesture on IOS 13?

Unfortunately, you can't disable three fingers gestures but you can use AssistiveTouch. Please Go to Settings > Accessibility > Touch > AssistiveTouch, then turn on AssistiveTouch. Then you see a button appear onscreen and You can drag the button to any edge of the screen.

What are finger gestures on iPhone?

Scroll, swipe, flick Slide one finger up and down or side to side—for example, to see items outside the edges of the screen or to see more options in a list. Scroll quickly by swiping or flicking one finger rapidly across the screen. Swipe or flick up and down to scroll the pages of your document.


2 Answers

In your handleViewsSwipe you can get the numberOfTouches property from the gesture recognizer.

- (void)handleViewsSwipe:(UISwipeGestureRecognizer *)recognizer {
    NSUInteger touches = recognizer.numberOfTouches;
    switch (touches) {
        case 1:
            break;
        case 2:
            break;
        case 3:
            break;
        default:
            break;
    }
}

Just switch the same method for what to do depending on how many touches you get.

like image 185
MobileOverlord Avatar answered Oct 19 '22 23:10

MobileOverlord


Add three swipe gesture recognizers to your view:

for (int i = 1; i <= 3; ++i) {
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleViewsSwipe:)];
    swipe.numberOfTouchesRequired = i;
    swipe.direction = UISwipeGestureRecognizerDirectionLeft;
    swipe.delaysTouchesBegan = YES;
    [self.view addGestureRecognizer:swipe];
}

Worked for me.

like image 44
rob mayoff Avatar answered Oct 19 '22 23:10

rob mayoff