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

  • Home
  • SEARCH
  • 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 6530635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:46:46+00:00 2026-05-25T09:46:46+00:00

For various reasons, I’ve moved these methods from a UIView subclass to my viewcontroller.

  • 0

For various reasons, I’ve moved these methods from a UIView subclass to my viewcontroller. And I finally got it working, except for one thing. Not only am I able to drag the UIImageviews I’ve programmatically created, but the actual view controllers view is draggable too. Creating this much undesired effect. I guess it’s the fact that it’s touches anyobject, and the background itself is an object. I’m just not sure how exclude the background. I would think that it would need the “UserInteraction enabled”, but I guess not? I only want it to make UIImageViews draggable. Please forgive my noobness. I’m still learning.

I have all the imageviews i’d want “touchable” in an NSMutableDictionary called “letterDictionary”. Would it be possible to only have touch apply to what’s in the dictionary?

https://i.stack.imgur.com/vdN1T.jpg

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    UITouch *touch = [touches anyObject];
    touchPoint = [touch locationInView:self.view];

    movingLetter = [touch view];

    CGPoint pointInside = [touch locationInView:[touch view]];
    if ([movingLetter pointInside:pointInside withEvent:event]) touchedInside = YES;

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    if (touchedInside) {
        UITouch *touch = [touches anyObject];
        CGPoint newPoint = [touch locationInView:self.view];  // get the new touch location
        movingLetter.center = CGPointMake(movingLetter.center.x + newPoint.x - touchPoint.x, movingLetter.center.y + newPoint.y - touchPoint.y);         
        touchPoint = newPoint;      
    }
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if (touchedInside) {
        UITouch *touch = [touches anyObject];
        CGPoint newPoint = [touch locationInView:self.view];

        movingLetter.center = CGPointMake(movingLetter.center.x + newPoint.x - touchPoint.x, movingLetter.center.y + newPoint.y - touchPoint.y);

        if (CGRectIntersectsRect([movingLetter frame], [placeHolder frame]))
            {
                movingLetter.center = placeHolder.center;
            }

    }   
    touchedInside = NO;
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    touchedInside = NO;
}
  • 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-25T09:46:46+00:00Added an answer on May 25, 2026 at 9:46 am

    You have the view that was touched,

        UITouch *touch = [touches anyObject];
        touchPoint = [touch locationInView:self.view];
        movingLetter = [touch view];
    

    just test to see if it is the class you are looking for (e.g. a UIImageView) then return

        UITouch *touch = [touches anyObject];
        if (![[touch view] isKindOfClass:[UIImageView class]])
        {
           return;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For various reasons, we are writing a new business objects/data storage library. One of
For various reasons (code review mostly) I need to switch from current development branch
Ahoy! I'm trying to create a reusable UIView (for various reasons) similar to the
For various reasons that aren't too germane to the question, I've got a table
If I've got a Java program that can exit for various reasons, like: because
i'm struggling with converting a menu from mootools to jquery. there are various reasons
I recently converted from MEF to Unity - for various reasons. I previously had
For various reasons I am stuck trying to remove a parent div from a
For various reasons I need to use AVPlayer to play music from the IOS
I writing a txt file using ofstream, from various reasons the file should have

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.