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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:22:04+00:00 2026-06-14T18:22:04+00:00

I’ve got two UIViews on my window: one to hold player scores, (a sidebar),

  • 0

I’ve got two UIViews on my window: one to hold player scores, (a sidebar), and a main play area. They both fit on the UIWindow, and neither scroll. The user can drag UIButtons around on the main play area – but at present, they can drop them onto the sidebar. Once they do, they can’t drag them again to bring them back, presumably because you’re then tapping on the second view, which doesn’t contain the button in question.

I’d like to prevent anything inside the main view being moved onto the sidebar view. I’ve managed this, but I need the drag to be released if the player’s finger moves off that view. With the code below, the button keeps moving with the finger, but just won’t go past the X coordinate of the view. How can I go about this? Dragging is enabled using this call:

[firstButton addTarget: self action: @selector(wasDragged: withEvent:) forControlEvents: UIControlEventTouchDragInside];

To this method:

- (void) wasDragged: (UIButton *) button withEvent: (UIEvent *) event
{
    if (button == firstButton) {
        UITouch *touch = [[event touchesForView:button] anyObject];
        CGPoint previousLocation = [touch previousLocationInView:button];
        CGPoint location = [touch locationInView:button];
        CGFloat delta_x = location.x - previousLocation.x;
        CGFloat delta_y = location.y - previousLocation.y;
        if ((button.center.x + delta_x) < 352)
        {
            button.center = CGPointMake(button.center.x + delta_x, button.center.y + delta_y);
        } else {
            button.center = CGPointMake(345, button.center.y + delta_y);
        }
    }
}
  • 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-14T18:22:05+00:00Added an answer on June 14, 2026 at 6:22 pm

    implement

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

    touch delegate method, then check the location of the UITouch, if the location is outside of the bounds you want to allow (the first view), then don’t move it any further. You could also kill the touch at the point the user drags outside the view using a BOOL iVar

    //In .h file
    BOOL touchedOutside;
    
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        touchedOutside = NO;
    }
    
    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        if (!touchedOutside) {  
            UITouch *touch = [[event allTouches] anyObject];
            CGPoint location = [touch locationInView:firstView];
    
              if (location.x < UPPER_XLIMIT && location.x > LOWER_XLIMIT) {
                  if (location.y < UPPER_YLIMIT && location.x > LOWER_YLIMIT) {
    
                      //Moved within acceptable bounds
                      button.centre = location;
                  }
              } else {
                  //This will end the touch sequence
                  touchedOutside = YES;
    
                  //This is optional really, but you can implement 
                  //touchesCancelled: to handle the end of the touch 
                  //sequence, and execute the code immediately rather than
                  //waiting for the user to remove the finger from the screen
                  [self touchesCancelled:touches withEvent:event];   
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from
i got an object with contents of html markup in it, for example: string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.