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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:17:21+00:00 2026-05-31T00:17:21+00:00

I have a custom slider-type object, that I wish to make more usable. Currently

  • 0

I have a custom slider-type object, that I wish to make more usable. Currently I use UIPanGestureRecognizer and translationInView to make it work. It works pretty well but I’d like some sort of velocity in there to make it feel a bit more useful. I’ve tried a few things but cant quite figure out how to properly implement velocity changedLevel equation.

- (void)panDetected:(UIPanGestureRecognizer *)gesture {

    CGPoint swipeLocation = [gesture locationInView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:swipeLocation];
    LevelCounterTableCell *swipedCell = (LevelCounterTableCell *)[self.tableView cellForRowAtIndexPath:indexPath];

    if([gesture state] == UIGestureRecognizerStateBegan) {
        NSString *originalLevelString = swipedCell.levelNumber.text;
        originalLevel = [originalLevelString intValue]; // int originalLevel
    }

    if ([gesture state] == UIGestureRecognizerStateChanged) {

        CGFloat xTranslation = [gesture translationInView:[[gesture view] superview]].x;
        CGFloat xVelocity = [gesture velocityInView: [[gesture view] superview]].x;

        // Pan threshold is currently set to 8.0. 
        // 8.0 is a decent level for slow panning
        // for fast panning 2.0 is more reasonable
        changedLevel = ceilf((xTranslation / panThreshold) + originalLevel); // int changedLevel

        // Raw velocity seems to go from around 3 (slow)
        // to over 200 (fast)
        NSLog(@"raw velocity = %f", xVelocity);

        if (changedLevel >= 15 && changedLevel <= 100) {
            swipedCell.levelNumber.text = [NSString stringWithFormat:@"%i", changedLevel];
            swipedCell.meter.frame = [self updateMeter: changedLevel];

        }
    }

    if ([gesture state] == UIGestureRecognizerStateEnded || [gesture state] == UIGestureRecognizerStateCancelled) {
        if (changedLevel >= 15 && changedLevel <= 100) {
            //... Save the values...            
        }

    }
}

Any help would be greatly appreciated. Thank you.

  • 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-31T00:17:22+00:00Added an answer on May 31, 2026 at 12:17 am

    In my experience, the velocityInView: of a pan gesture recognizer isn’t important until the user lifts their finger(s) and the recognizer finishes. At that point, you can use the velocity to calculate an animation duration to move your views.

    Just stick with translationInView: until the state is UIGestureRecognizerStateEnded and then use velocityInView: to animate any onscreen view changes.

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

Sidebar

Related Questions

I have custom slider that I use the following touch event to respond to:
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have a custom event that is dispatched when a slider is moved but
I have a multiple jQuery slider and write custom style for that , in
I have custom coded several enterprise applications for mid to large organizations to use
I have a few models that need to have custom find conditions placed on
I'm looking into some XSS prevention in my Java application. I currently have custom
I have a view with a custom slider. We are using a subclass of
I have a simple custom UIView (a rectangle) that is implemented with drawRect. The
I have customised my SeekBar - I use a custom image as the background,

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.