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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:57:16+00:00 2026-06-07T11:57:16+00:00

I added to my main UIView a subview (called panel ) and i added

  • 0

I added to my main UIView a subview (called panel) and i added gestureRecognizer to it because i want it to be draggable only for the Y axis and only for certain limits (i.e. 160, 300, over 300 it can’t go).

I implemented the gesture handling that way

- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
    CGPoint translation = [recognizer translationInView:self.view]; 
    recognizer.view.center = CGPointMake(self.view.frame.size.width/2, recognizer.view.center.y + translation.y);
    [recognizer setTranslation:CGPointMake(0, 0) inView:self.view.superview];

    //now limit the drag to some coordinates
   if (y == 300 || y == 190){
       no more drag
    }
}

but now i don’t know how to limit the drag to those coordinates.

It’s not a huge view, it’s just a small view containing a toolbar and a button.

How can i limit the drag to a coordinate? (x = 160(middle screen), y =404 ) <- example

What should the center be there?

I googled a lot but i didn’t find a concrete answer.

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-07T11:57:19+00:00Added an answer on June 7, 2026 at 11:57 am

    First, you need to enforce the limit before you change the view’s center. Your code changes the view’s center before checking if the new center is out of bounds.

    Second, you need to use the correct C operators for testing the Y coordinate. The = operator is assignment. The == operator tests for equality, but you don’t want to use that either.

    Third, you probably don’t want to reset the recognizer’s translation if the new center is out-of-bounds. Resetting the translation when the drag goes out of bounds will disconnect the user’s finger from the view he’s dragging.

    You probably want something like this:

    - (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
        CGPoint translation = [recognizer translationInView:self.view];
    
        // Figure out where the user is trying to drag the view.
        CGPoint newCenter = CGPointMake(self.view.bounds.size.width / 2,
            recognizer.view.center.y + translation.y);
    
        // See if the new position is in bounds.
        if (newCenter.y >= 160 && newCenter.y <= 300) {
            recognizer.view.center = newCenter;
            [recognizer setTranslation:CGPointZero inView:self.view];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main view to which I have added a subview using the
I have a UIPickerView added as a subview to my main view. I also
I have a bunch of UIView on my main view. I have added the
I'm developing an android game, and just added a main menu. This is a
I've created a new Pylons application and added a controller (main.py) with a template
I added some UI elements to the main.xml file in the res\layout folder and
I have one main project and another project which is added as a subprojects.
I just added an ExecutionHandler to my server pipeline just before my main business
The scenario: in Main, instances of class Bullet are spawned and added to the
I subclassed UIScrollView Then created an object of it in the main class. Added

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.