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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:47:26+00:00 2026-05-29T22:47:26+00:00

This question has some relation to this post I made recently: Drag a UIView

  • 0

This question has some relation to this post I made recently: Drag a UIView part-way, then it moves on its own

In short, I have a draggable UI view partly visible at the bottom of the window. There is a “pull tab” that the user can use to drag the view upwards or downwards on the screen. I have placed limits on the Y position for the upper and lower positions using this code, but I have no clue if this is the right way to do it:

- (void)panPiece:(UIPanGestureRecognizer *)gestureRecognizer
{
    UIView *piece = [gestureRecognizer view];
    [self adjustAnchorPointForGestureRecognizer:gestureRecognizer];

    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged)
    {
        CGPoint velocity = [gestureRecognizer velocityInView:[piece superview]];
        CGPoint translation = [gestureRecognizer translationInView:[piece superview]];

        if(velocity.y < 0)  //user is dragging the view upwards the screen
        {
            // Set the maximum Ypos as the top 1/3rd of the screen
            CGFloat maxYPos = self.view.frame.size.height/3;
            if(blogTextView.frame.origin.y >= maxYPos)
            {
                [piece setCenter:CGPointMake([piece center].x, [piece center].y + translation.y)];
                [gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
            }
        }
        else
        {
            // User is dragging the view downwards the screen
            // Set the lowest Y position to be 420
            if(blogTextView.frame.origin.y <= 420) //size of remaining view
            {
                [piece setCenter:CGPointMake([piece center].x, [piece center].y + translation.y)];
                [gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
            }
        }
    }

}

I think this looks ugly, but it works if the user is dragging the view slowly. The problem is if the user drags the view very rapidly upward or downward the screen, then the view can be pulled beyond the limits I put on the Y position. For example, in the default state with the draggable view on the bottom, I was able to drag the view in a snap-like speed all the way to over the navigation bar!

Is there a correct way to set the limits of how far a view can be dragged and will be dealt with correctly in this gestureRecognizer callback?

For reference, here are pics of the test app:

Default screen with draggable view at the bottom and the pull tab

View dragged up to its correct max Y position

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-29T22:47:27+00:00Added an answer on May 29, 2026 at 10:47 pm

    The problem is that in the following code:

    if(blogTextView.frame.origin.y >= maxYPos)
    {
        [piece setCenter:CGPointMake([piece center].x, [piece center].y + translation.y)];
        [gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
    }
    

    And this one:

    if(blogTextView.frame.origin.y <= 420) //size of remaining view
    {
        [piece setCenter:CGPointMake([piece center].x, [piece center].y + translation.y)];
        [gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
    }
    

    You you should use the future value of blogTextView.frame.origin.y (the value that you would obtain if you executed the code inside the if bloc.)

    In other words, you are always doing an extra translation. And you can’t notice that when dragging slowly because the extra translation is not important, but it becomes important when dragging quickly and you can notice the wrong result.

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

Sidebar

Related Questions

This question has been bugging me for some time. I always picture launching my
This question has in the back of my mind for some time, sorry if
I believe this questions has been asked in some or the other way but
This question has been the subject of some lively discussions in my team. My
I'm sure this question has been asked over and over again, but for some
I feel that this question has been asked 10^78 times, but for some reason,
I know this question has been asked before, but I'm having some difficulty getting
This question has been asked before ( link ) but I have slightly different
This question has been discussed in two blog posts ( http://dow.ngra.de/2008/10/27/when-systemcurrenttimemillis-is-too-slow/ , http://dow.ngra.de/2008/10/28/what-do-we-really-know-about-non-blocking-concurrency-in-java/ ),
This question has spawned out of this one. Working with lists of structs in

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.