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

  • SEARCH
  • Home
  • 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 8011079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:55:27+00:00 2026-06-04T18:55:27+00:00

How do you implement a swipe with an UIGestureRecognizer subclass? (in case you’re wondering

  • 0

How do you implement a swipe with an UIGestureRecognizer subclass?

(in case you’re wondering why I’d like to do this instead of using UISwipeGestureRecognizer, it’s because I want to add swipe recognition to Chameleon‘s UIKit port)

  • 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-06-04T18:55:28+00:00Added an answer on June 4, 2026 at 6:55 pm

    My first go at it (also on Github):

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        _beganLocation = [touch locationInView:self.view];
    }
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        CGPoint movedLocation = [touch locationInView:self.view];
        CGFloat distance = _distance(_beganLocation, movedLocation);
    
        if (distance < SWIPE_MIN_DISTANCE) return;
    
        CGFloat angle = _angle(_beganLocation, movedLocation);
        int direction = -1;
        if (angle > 270 - SWIPE_MAX_ANGLE && angle < 270 + SWIPE_MAX_ANGLE) {
            direction = UISwipeGestureRecognizerDirectionUp;
        }
        if (angle > 180 - SWIPE_MAX_ANGLE && angle < 180 + SWIPE_MAX_ANGLE) {
            direction = UISwipeGestureRecognizerDirectionLeft;
        }
        if (angle > 90 - SWIPE_MAX_ANGLE && angle < 90 + SWIPE_MAX_ANGLE) {
            direction = UISwipeGestureRecognizerDirectionDown;
        }
        if ((angle > 360 - SWIPE_MAX_ANGLE && angle <= 360) || (angle >= 0 && angle <= SWIPE_MAX_ANGLE)) {
            direction = UISwipeGestureRecognizerDirectionRight;
        }
    
        if (direction == -1) {
          self.state = UIGestureRecognizerStateFailed;
        } else {
          self.state = self.direction == direction ? UIGestureRecognizerStateRecognized : UIGestureRecognizerStateFailed;
        }
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        self.state = UIGestureRecognizerStateFailed;
    }
    
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
        self.state = UIGestureRecognizerStateFailed;
    }
    

    Auxiliary functions:

    static CGFloat _distance(CGPoint point1,CGPoint point2)
    {
        CGFloat dx = point2.x - point1.x;
        CGFloat dy = point2.y - point1.y;
        return sqrt(dx*dx + dy*dy);
    };
    
    static CGFloat _angle(CGPoint start, CGPoint end)
    {
        CGPoint origin = CGPointMake(end.x - start.x, end.y - start.y); // get origin point to origin by subtracting end from start
        CGFloat radians = atan2f(origin.y, origin.x); // get bearing in radians
        CGFloat degrees = radians * (180.0 / M_PI); // convert to degrees
        degrees = (degrees > 0.0 ? degrees : (360.0 + degrees)); // correct discontinuity
        return degrees;
    }
    

    It should be noted that Chameleon‘s implementation of gesture recognizers is incomplete and contains logic most likely specific to Twitterrific. Our fork contains further modifications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I implement a custom swipe animation instead of the standard horizontal movement?
I want to implement the handling of an additional swipe gesture in my UITableViewController.
Actually i want to implement swipe left and right in UIScrollview. i have scrollview
i want to hide the bar of the UIPageControl, because i want to implement
I want to implement all possible Gesture recognizers on image,like rotate gesture recognizer zoom
I want to implement functionality same like in Facebook album viz. first it show
I want to implement something like the Android Calendar week view, where you can
I am trying to implement SMS kind of swipe and delete functionality. In case
I have customized a UITableViewCell and I want to implement swipe to delete. But
I would like to implement onfling (or some similar swipe) in listview in each

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.