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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:34:56+00:00 2026-05-27T07:34:56+00:00

I am using a UIPanGestureRecognizer to allow my UITableView to be dragged around. I

  • 0

I am using a UIPanGestureRecognizer to allow my UITableView to be dragged around. I have currently set it so that the UITableView cannot be dragged past 0 or half its width. But now, its frame is set to 0 when I try and drag the UITableView back to 0 from an origin of greater than 0. How can I prevent this and allow dragging of the UITableView back to 0? I have tried the following, but I can’t quite find out why the outlined code is causing this.

- (void) handlePan:(UIPanGestureRecognizer *) pan {

    CGPoint point = [pan translationInView:_tableView];

    CGRect frame = [_tableView frame];

    if (point.x <= _tableView.frame.size.width / 2) {
        frame.origin.x = point.x;
    }

    NSLog(@"%f : %f", frame.origin.x, _tableView.frame.origin.x);
    //outline begin!
    if (frame.origin.x < 0 && _tableView.frame.origin.x >= 0) {
        frame.origin.x = 0;
    }
    //outline end!
    isFilterViewShowing = frame.origin.x > 0;

    [_tableView setFrame:frame];

}
  • 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-27T07:34:57+00:00Added an answer on May 27, 2026 at 7:34 am

    This is not the prettiest code, but that is working in the simulator.
    For this code to work you need to add an instance variable.
    This code may not behave exactly as you want it, because it’s keeping track of “negative” x position, so you get some “threshold” effect that you may not want depending on you design choice.

    - (void) handlePan:(UIPanGestureRecognizer *) pan {
    
    if (pan.state == UIGestureRecognizerStateBegan)
    {
        //  cache the starting point of your tableView in an instance variable
        xStarter = _tableView.frame.origin.x;
    }
    
    // What is the translation
    CGPoint translation = [pan translationInView:self.tableView];
    //  Where does it get us
    CGFloat newX = xStarter + translation.x;
    
    CGFloat xLimit = self.tableView.superview.bounds.size.width / 2;
    
    if (newX >= 0.0f && newX <= xLimit)
    {
        //  newX is good, don't touch it
    }
    else if (newX < 0)
    {
        newX = 0;
    }
    else if (newX > xLimit)
    {
        newX = xLimit;
    }
    
    CGRect frame = self.tableView.frame;
    frame.origin.x = newX;
    
    [_tableView setFrame:frame];
    
    if (pan.state == UIGestureRecognizerStateEnded)
    {
        //  reset your starter cache
        xStarter = 0;
    }
    }
    

    Have you notice how [pan translationInView:aView]; is returning the offset of the pan gesture and not the position of the finger on the screen.
    That is why your code don’t work as you expect.

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

Sidebar

Related Questions

I have a UIView object that can be dragged around using UIPanGestureRecognizer, but I
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I have set up some gesture recognition in an app that I'm building. One
Using report builder 3.0, I have a report that queries a cube. How do
I'm using a UIPanGestureRecognizer to recognize horizontal sliding in a UITableView (on a cell
I have code that changes the color of navigation bar using appearance attribute. I
I have an image that I would like to set up to respond to
Using online interfaces to a version control system is a nice way to have
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using JDeveloper , I started developing a set of web pages for a project

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.