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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:01:09+00:00 2026-06-05T22:01:09+00:00

Hey I know there are already a few posts about this – yet I

  • 0

Hey I know there are already a few posts about this – yet I still can’t find an adequate answer for the problem I’m having.

Just new to cocoa and iOS, I’m in the middle of developing my first iOS game. In this game I would like to be able to calculate the speed of a user’s swipe. I’m having no difficulty finding the distance between successive touches in the swipe motion, but am having difficulty determining the time elapsed between the touches

  • in touchesMoved: I do calculations with the current touch as well as keep track of the last previously recorded touch as a UITouch

  • in touchesEnded: I now want to calculate the speed of swipe, but when I do something like:

    double timeDelay = event.timestamp – self.previousTouch.timestamp;

this always returns 0.

However, using gcc I’m able to see that the two timestamps are in fact NOT the same. Additionally, upon inspecting I saw that the NSTimeInterval values for these events were on the magnitude of ~ 10^(-300). This seems odd as an NSTimeInterval is supposed to report seconds since system start up is it not?

I’ve also tried keeping track of the NSDate of the previous touch and use it with conjunction with [NSDate timeIntervalSinceNow]. This yielded even stranger results, returning a value around 6 every time. Again, since timerIntervalSinceNow returns a NSTimeInterval, this value is very strange.

What am I not understanding about timestamps? events?
Any help on this would be greatly appreciated!
Thanks for your time

some supporting code:

In sampleController.h:

@property(nonatomic) UITouch* previousTouch
@property(nonatomic) UITouch* currentTouch

In sampleController.m:

@synthesize previousTouch = _previousTouch, currentTouch = _currentTouch;
...
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
       self.currentTouch = [[event allTouches] anyObject];
       // do stuff with currentTouch
}
...
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
       self.previousTouch = self.currentTouch;
       self.currentTouch = [[event allTouches] anyObject];
       // do stuff with currentTouch
}
...
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
       float distanceMoved = [self.touch locationInView:self.playView].x - 
              [self.touch previousLocationInView:self.playView].x;
       // attempt 1
       double timeElapsed = self.currentTouch.timestamp - self.previousTouch.timestamp;

       // attempt 2
       double timeElapsed = event.timestamp - self.previousTouch.timestamp;

       // do stuff with distanceMoved and timeDelay
}
  • 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-05T22:01:11+00:00Added an answer on June 5, 2026 at 10:01 pm

    The UIPanGestureRecognizer has a velocityInView proerty that you may find of use. Docs are here

    Also you may find this ray wenderlich tutorial informative.

    (and this isn’t a smack – but a few google searches turn up loads of material on this sort of thing. Saves all the hair-pulling for the the larger life questions 😉

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

Sidebar

Related Questions

I already know there's answers for this kind of thing, but I don't really
Hey. I know this is not a 'refactor my code' site but I made
Hey, I don't have any code because I don't know how to do this.
I am having difficulty in this conversion. I don't know if there is a
Hey, I'd like to know if there is a way to know if the
Hey there stack overflow enthusiasts. I am getting this mixed content warning in Internet
Hey, i'm creating an application and would like to know, is there a way
Hey all, I know there are a lot of questions out there for matching
Hey guys, I know that there are a million questions on random numbers, but
I know there are a bunch of SMS gateway related questions on this site

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.