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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:43:45+00:00 2026-05-19T16:43:45+00:00

I have a few UIView subclasses that exist in a kind of inventory. When

  • 0

I have a few UIView subclasses that exist in a kind of inventory. When you tap one, another draggable version is placed over top of it. I want the inventory versions to stay put while you drag others around. The code to make a duplicate works but dragging your finger around doesn’t move it.

If I release and then start dragging the newly created version it moves as expected. I think this is because the original touches (that made the dupe) didn’t have the draggable version in the responder chain.

A little code…

in my stationary “icon”…

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    [self.viewController placeDraggableItem:self.item WithPoint:self.frame.origin];
}

in my viewController…

- (void)placeDraggableItem:(Item *)item WithPoint:(CGPoint)point
{
    DraggableItem *draggableItem = [[DraggableItem alloc] initWithImage:[UIImage imageNamed:item.graphic]];
draggableItem.frame = CGRectMake(point.x, scrollView.frame.origin.y + point.y, 64.0f, 64.0f);
    [self.view addSubview:draggableItem];   
    [draggableItem release];
}

in my DraggableItem…

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    currentPoint = [[touches anyObject] locationInView:self];
}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    CGPoint activePoint = [[touches anyObject] locationInView:self];
    CGPoint newPoint = CGPointMake(self.center.x + (activePoint.x - currentPoint.x), self.center.y + (activePoint.y - currentPoint.y));

    float midPointX = CGRectGetMidX(self.bounds);
    if (newPoint.x > self.superview.bounds.size.width  - midPointX)
        newPoint.x = self.superview.bounds.size.width - midPointX;
    else if (newPoint.x < midPointX)  // If too far left...
        newPoint.x = midPointX;

    float midPointY = CGRectGetMidY(self.bounds);
    if (newPoint.y > self.superview.bounds.size.height  - midPointY)
        newPoint.y = self.superview.bounds.size.height - midPointY;
    else if (newPoint.y < midPointY)  // If too far up...
        newPoint.y = midPointY;

    self.center = newPoint;
}

Now again creating the draggable version works. And the draggable version is able to be moved after you first release your first touch. But I think I need to get the newly create UIView to respond to touches that were originally made for the “icon”.

Any ideas?

I’m aware this question is kind of similar to this one: How to "transfer" first responder from one UIView to another? but in that case the view which should receive the touches is already there whereas I need to pass touches onto a newly created view.

  • 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-19T16:43:46+00:00Added an answer on May 19, 2026 at 4:43 pm

    I don’t know of any way to hand touches off to a newly created view, though that doesn’t mean there isn’t a way to do it. It looks like you really only want your draggable view to handle the touches, I would probably create each draggable view with with an alpha of 0 at the same time you create the non draggable views, and in touchesBegan set it to 1. If your non-draggable views don’t need to handle touches, then it doesn’t make sense to make them handle touches just to pass them along.

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

Sidebar

Related Questions

I have a tableViewHeader UIView that contains a few dynamic elements (UILabels with varying
I have added a few buttons to self.view. When the user clicks on one
I have one UITextView which is on the bottom of view. When user tap
I have a class that implements UIView and inside - (void)drawRect:(CGRect)rect method I add
I have a custom UIView that is composed entirely of CALayers. In the awakeFromNib
My application has a few portions that have really big buttons (640x130, 230x150, etc.)
I have drawn a UIView and then few CALayers as sublayers on its root
Through storyboard, I have added a UIView (say Y) to another UIView (say X).
I have a few UITextFields (within UITableViewCells) on my UIView with a Save UIButton.
I have a custom UIView class that I want to spin, shrink and move

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.