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 8555369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:06:27+00:00 2026-06-11T15:06:27+00:00

I am creating a custom gesture recognizer, and my goal is to log movement

  • 0

I am creating a custom gesture recognizer, and my goal is to log movement above a certain threshold for the duration of the gesture, then report that data set at the end of the gesture. I’m a little fuzzy about the role that the gesture recognizer object plays.

As I am still a bit new to OOP, I am wondering about the best practice for MVC with this gesture recognizer. Specifically, should the gesture recognizer be “dumb” and only report movement to a view controller, and let the logic and logging happen in the VC, or is it just as fine to do light logic and logging in the gesture recognizer, then let it report back when the gesture is finished, and have the VC ask the gesture recognizer for the data.

Here is some sample code for what I’m currently prototyping (with the approach of having the logic and logging in the gesture recognizer):

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesMoved:touches withEvent:event];
    if (self.state == UIGestureRecognizerStateFailed) return;

    CGPoint nowPoint = [[touches anyObject] locationInView:self.view];
    int xMovement = nowPoint.x - self.previousPoint.x;
    int yMovement = nowPoint.y - self.previousPoint.y;

    if (xMovement >= 0) {
        // positive/no x movement, log points if x or y has movement above threshold
        if (xMovement > MovementThreshold || yMovement > MovementThreshold) {
            NSLog(@"Movement above the threshold!\nx: %f\ty: %f", nowPoint.x, nowPoint.y);
            self.previousPoint = nowPoint;
        }
    } else {
        // negative x movement
        self.state = UIGestureRecognizerStateFailed;
    }
}
  • 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-11T15:06:28+00:00Added an answer on June 11, 2026 at 3:06 pm

    I’d go the logging in the gesture recognizer object. I look at it this way.

    If I ever want to use this gesture recognizer with logging anywhere else, what will I have to do? If your logging is in the view controller then you have to cut and paste that code. If the logging is in the gesture recognizer you just create a new instance of the gesture recognizer.

    If I ever want to remove the gesture recognizer from this view controller, what do I need to do? Again, if your logging code is in the view controller it will be a lot more work.

    Encapsulation tells me I want to keep my code in the gesture recognizer.

    That said, your gesture recognizer doesn’t have to be a single object. It could be small set. One for the gesture recognizer itself, one for the act of logging and one for the storage of the data. It really depends on how complicated each task is. If each new data point is just adding a single number to an array, then it seems premature to break it apart, but if it’s data you are going to want to pass around independent of the gesture recognizer itself, then it might be better to break it out.

    If you decide you made the wrong choice, that’s what re-factoring is for. 🙂

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

Sidebar

Related Questions

i am creating custom listview. passing data to the edittext . at that time
I need to implement creating custom gesture(like Gesture Builder in Android ) in my
I am creating custom Swing components and want to provide a UI that looks
I'm creating custom control that contain multiple parts. Inside template creation I'm subscribing for
I am creating custom images that I later convert to an image pyramid for
I am having some problems creating custom types for my data table, using jquery.datatables.js.
Creating custom IHttpModules, I have realized that the requests for static files (e.g.: .css
I'm looking for tutorials on creating custom view transitions. In particular, transitions that involve
In WPF, we are creating custom controls that inherit from button with completely drawn-from-scratch
I know that there are tons of links about creating custom configuration sections out

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.