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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:00:56+00:00 2026-06-09T09:00:56+00:00

I have a UIView and on the top of him I’ve got UIButton, UITableView

  • 0

I have a UIView and on the top of him I’ve got UIButton, UITableView and UINavigationBar. what I want to do is, when you click on the UIButton and drag it, all the view will move to the left side only, until the screen ends. I mean that you can drag the view to the left and when you stop touching, the view will stop where your finger stopped touching the screen.

I can’t do it, he shows me only the “Touches Began 1” and thats it. what seems to be my problem here?

Thanks alot everyone!

float oldX, oldY;
BOOL dragging;

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    NSLog("Touches Began 1");
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self.view];

    if (CGRectContainsPoint(btnOpen.frame, touchLocation))
    {
        NSLog("Touches Began 2");
        dragging = YES;
        oldX = touchLocation.x;
        oldY = touchLocation.y;
    }
}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self.view];

    if (dragging)
    {
        NSLog("Dragging!");
        CGRect frame = mainView.frame;
        frame.origin.x = mainView.frame.origin.x + touchLocation.x - oldX;
        frame.origin.y =  mainView.frame.origin.y + touchLocation.y - oldY;
        mainView.frame = frame;
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog("Touches Ended!");
    dragging = NO;
}


- (void)viewDidLoad
{    
    [btnOpen addTarget:self action:@selector(touchesBegan:withEvent:) forControlEvents: UIControlEventTouchDown];
    [btnOpen addTarget:self action:@selector(touchesMoved:withEvent:) forControlEvents: UIControlEventTouchDragInside];
    [btnOpen addTarget:self action:@selector(touchesEnded:withEvent:) forControlEvents: UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
}
  • 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-09T09:00:57+00:00Added an answer on June 9, 2026 at 9:00 am
    - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
    {
        NSLog("Touches Began 1");
    for (UITouch *touch in touches) {
        //UITouch *touch = [[event allTouches] anyObject];
        CGPoint touchLocation = [touch locationInView:self.view];
    
        if (CGRectContainsPoint(btnOpen.frame, touchLocation))
        {
            NSLog("Touches Began 2");
            //dragging = YES;
            oldX = touchLocation.x;
            oldY = touchLocation.y;
        }
    }
    }
    
    - (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
    {
       // UITouch *touch = [[event allTouches] anyObject];
    for (UITouch *touch in touches) {
        CGPoint touchLocation = [touch locationInView:self.view];
    
        if (CGRectContainsPoint(btnOpen.frame, touchLocation))
        {
            NSLog("Dragging!");
            CGRect frame = mainView.frame;
            frame.origin.x = mainView.frame.origin.x + touchLocation.x - oldX;
            frame.origin.y =  mainView.frame.origin.y + touchLocation.y - oldY;
            mainView.frame = frame;
        }
    }
    }
    

    Try like this i think it will be helpful to you.

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

Sidebar

Related Questions

I have a UINavigationController/UITableView and I want to present a UIView over top of
if I have the following view hierarchy UIView --- top level view --UIButton --UIView
I have a UIView on top of another view that's using a UITouchGesture. The
I have a UIView that gets added to my UITableView .view as a subview.
I have a UIView(first view) on top of which I would like to display
I'm trying to have a modular uiview that will be placed on top of
I have a subclass of UIView on top of a UITableView . I am
I have a working UIButton in my view controller's view. I have a UIView
I have a UIView -- call it HomeView that contains a UITableView and a
I have a question about CATransform3D, I want to transform a view about 90

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.