Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4347686
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:20:26+00:00 2026-05-21T12:20:26+00:00

I was wondering if there is an easy method to set the minimum swipe

  • 0

I was wondering if there is an easy method to set the minimum swipe length, i.e. the length in pixel the user needs to swipe so that the gesture is recognised as a swipe.

I noticed that the normal swipe can be quite unresponsive (as compared to swiping photos in your photo library for instance).

This is the normal way, but I would like to reduce the required length of the swipe:

    - (void)viewDidLoad 
    {


    // SWIPING GESTURES:

    UISwipeGestureRecognizer *swipeLeftRecognizer;
    swipeLeftRecognizer=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(foundLeftSwipe:)];
    swipeLeftRecognizer.direction=UISwipeGestureRecognizerDirectionLeft;
    //swipeRecognizer.numberOfTouchesRequired=1;
    [self.view addGestureRecognizer:swipeLeftRecognizer];
    [swipeLeftRecognizer release];

    UISwipeGestureRecognizer *swipeRightRecognizer;
    swipeRightRecognizer=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(foundRightSwipe:)];
    swipeRightRecognizer.direction=UISwipeGestureRecognizerDirectionRight;
    //swipeRecognizer.numberOfTouchesRequired=1;
    [self.view addGestureRecognizer:swipeRightRecognizer];
    [swipeRightRecognizer release];


    [super viewDidLoad];
}

#pragma mark -
#pragma mark Swipes

- (void)foundLeftSwipe:(UISwipeGestureRecognizer *)recognizer {
    // do something
}

- (void)foundRightSwipe:(UISwipeGestureRecognizer *)recognizer {
    // do something
    }

I remember that there is a way to get the pixel start position and end position and then compare the two, but was just wondering if there is a simpler method, i.e. by simply defining a value for the minimum required swipe length in the code I have here.


EDIT:

This is how I recoded the whole thing:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    gestureStartPoint = [touch locationInView:self.view];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint currentPosition = [touch locationInView:self.view];

    CGFloat deltaXX = (gestureStartPoint.x - currentPosition.x); // positive = left, negative = right
    CGFloat deltaYY = (gestureStartPoint.y - currentPosition.y); // positive = up, negative = down

    CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); // will always be positive
    CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); // will always be positive

    if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
        if (deltaXX > 0) {
                label.text = @"Horizontal Left swipe detected";
                [self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
            }
        else {
                label.text = @"Horizontal Right swipe detected";
                [self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
            }

    }


    if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
        if (deltaYY > 0) {
            label.text = @"Vertical up swipe detected";
            [self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
            }
        else {
            label.text = @"Vertical down swipe detected";
            [self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
        }


    }



}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:20:26+00:00Added an answer on May 21, 2026 at 12:20 pm

    Please see this documentation http://developer.apple.com/library/ios/#documentation/uikit/reference/UIResponder_Class/Reference/Reference.html

    You can use touchesBegan, touchesMoved, and touchesEnded methods to find the start/end positions of the swipe. By finding the delta between the start and the end, you can get the swipe length.

    Maybe something like this.

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
        UITouch *touch = [touches anyObject];
        gestureStartPoint = [touch locationInView:self.view];
    
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
        CGPoint gestureEndPoint = [touch locationInView:self.view];   
    
        // compare gestureStartPoint and gestureEndPoint to determine swipe length
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering if there is an easy way to add the functionality to duplicate
I was wondering if there was an easy way in SQL to convert an
I'm wondering if there is a quick and easy function to clean get variables
was wondering if there are anyone else here that has signed up with the
I wanted to know if there is any (easy) method to find the order
Is there any easy way to convert a URL that contains to two-byte characters
Wondering if there is any Text to Speech software available as a plug in
Wondering if there's any not-too-hard way to edit non-form text in html 4. I
Just wondering if there is any way (in C) to get the contents of
Just wondering if there is a better way to write the following PL/SQL piece

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.