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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:52:33+00:00 2026-06-08T11:52:33+00:00

In my app i want to create a custom gesture recognizer that recognizes a

  • 0

In my app i want to create a custom gesture recognizer that recognizes a long press followed by a swipe.
I need to measure if the length of the long press is more than 1 second. If it is, then call a function and wait for the swipe action to begin.

My problem is that I the only way i know now how long the press was is by extracting the timestamp of touchesBegan from touchesMoved. However i want to know that elapsed time before touchesMoved gets called.

Is there a way to know the length of the tap before the touchesMoved is called?

Thanks in advance!

  • 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-08T11:52:34+00:00Added an answer on June 8, 2026 at 11:52 am

    you can use may code, it can use, but maybe you should deal with some details

    in the .h file you should add these ivar:

        TestView *aView ;//the view which you press
        NSThread *timerThread;              
        NSTimer *touchTimer;    
    
        NSDate *touchStartTime;         
        CGPoint touchStartPoint;            
        CGPoint lastTouchPoint;
    

    in the .m file you should add these method:

    - (void)doSomething
    {
        NSLog(@"Long press!!!");
    }
    
    
    - (void)startTimerThead{
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    
        touchTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
                                                      target:self 
                                                    selector:@selector(checkTouchTime:) 
                                                    userInfo:nil repeats:YES];
    
        [runLoop run];
        [pool release];
    }
    
    - (void)stopTouchTimer{
        if (touchTimer != nil) {
            [touchTimer invalidate];
            touchTimer = nil;
        }
        if (timerThread != nil) {
            [timerThread cancel];
            [timerThread release];
            timerThread = nil;      
        }
    }
    
    #define DELETE_ACTIVING_TIME 1.0
    
    - (void)checkTouchTime:(NSTimer*)timer{
    
                NSDate *nowDate = [NSDate date];
                NSTimeInterval didTouchTime = [nowDate timeIntervalSinceDate:touchStartTime];
                if (didTouchTime > DELETE_ACTIVING_TIME){
    
    
                    [self stopTouchTimer];
                    [self doSomething];
                }   
    
    
    }
    
    
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        UITouch *touch = [touches anyObject];
        UIView *touchView = [touch view];
        if ([touchView isKindOfClass:[TestView class]]) {
    
            touchStartTime = [[NSDate date] retain];
    
                if (nil == timerThread) {
                    timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerThead) object:nil];
                    [timerThread start];
                }
            }
            touchStartPoint = [touch locationInView:self.view];
            lastTouchPoint = touchStartPoint;
    }
    
    #define TOUCH_MOVE_EFFECT_DIST 10.0f
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
        CGPoint movedPoint = [touch locationInView:self.view];
    
        CGPoint deltaVector = CGPointMake(movedPoint.x - touchStartPoint.x, movedPoint.y - touchStartPoint.y);
    
            if (fabsf(deltaVector.x) > TOUCH_MOVE_EFFECT_DIST
                || fabsf(deltaVector.y) > TOUCH_MOVE_EFFECT_DIST) 
            {
    
                [self stopTouchTimer];
            }
    }
    
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{   
        UITouch *touch = [touches anyObject];
        UIView *touchView = [touch view];
        CGPoint movedPoint = [touch locationInView:self.view];
        CGPoint deltaVector = CGPointMake(movedPoint.x - touchStartPoint.x, movedPoint.y - touchStartPoint.y);
    
        if ([touchView isKindOfClass:[TestView class]]) {
                if (fabsf(deltaVector.x) < TOUCH_MOVE_EFFECT_DIST
                    && fabsf(deltaVector.y) < TOUCH_MOVE_EFFECT_DIST) {
                    [self stopTouchTimer];
                }
            }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a custom tab bar for an iphone app that looks
I want to create an app that uses the user's custom font, therefore I
UNIQLO's new alarm app has a custom UIDatePicker : And I want to create
I want to create App that Make My Device with multi-Users username and password
I want to create an Android app that can be used on 2.3.3 all
I want to create a web app that lets me create, store and display
I want to create a simple app that shows me the city of the
I need to allow the users of my web app to create custom forms.
In my flex app there are a few custom components. I want to create
I'm trying to create a custom control for a silverlight app that will basically

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.