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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:31:32+00:00 2026-06-04T19:31:32+00:00

based on how to add on touch and detect UIImageView on view so i

  • 0

based on how to add on touch and detect UIImageView on view so i could move it around and not adding one on top of it?

i got around of checking CGRectIntersectsRect single uiimageview. how will i need to check multiple uiimageview?

CORRECT

enter image description here

WRONG

enter image description here

-(void)initImagesAndGesture
{
    UIImage *img = [UIImage imageNamed:@"beer.png"];
    imgView1 = [[UIImageView alloc]initWithImage:img];
    [imgView1 setFrame:CGRectMake(0, 0, 75, 115)];
    [imgView1 setUserInteractionEnabled:YES];
    UIPanGestureRecognizer *recognizer1 = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan1:)];
    [imgView1 addGestureRecognizer:recognizer1];
    [self.view addSubview:imgView1];

    img = [UIImage imageNamed:@"cups.png"];
    imgView2 = [[UIImageView alloc]initWithImage:img];
    [imgView2 setFrame:CGRectMake(200, 240, 64, 75)];
    [imgView2 setUserInteractionEnabled:YES];
    recognizer1 = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan1:)];
    [imgView2 addGestureRecognizer:recognizer1];
    [self.view addSubview:imgView2];
}

-(void)handlePan1:(UIPanGestureRecognizer *)recognizer
{
    if (!(CGRectIntersectsRect(imgView1.frame, imgView2.frame)))
    {
        CGPoint pre_moveLocation = [recognizer locationInView:recognizer.view];
        NSLog(@"previous location %@",NSStringFromCGPoint(pre_moveLocation));        

        CGPoint translation = [recognizer translationInView:self.view];
        recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, 
                                             recognizer.view.center.y + translation.y);

        [recognizer setTranslation:CGPointMake(0, 0) inView:recognizer.view];
    }
    else 
    {
        NSLog(@"intersect!");

        CGPoint pre_moveLocation = [recognizer locationInView:recognizer.view];
        NSLog(@"previous location %@",NSStringFromCGPoint(pre_moveLocation));
        recognizer.view.center = CGPointMake(pre_moveLocation.x, pre_moveLocation.y);

        [recognizer setTranslation:CGPointMake(0, 0) inView:recognizer.view];

        //[imgView2 setFrame:CGRectMake(200, 240, 64, 75)];
        //[imgView1 setFrame:CGRectMake(0, 0, 75, 115)];

    }
}




-(void)addImgView:(UIPanGestureRecognizer *)recognizer
{
    NSLog(@"tappppp");

    UIImage *img = [UIImage imageNamed:@"beer.png"];
   UIImageView *imgView = [[UIImageView alloc]initWithImage:img];

    CGPoint tapLocation = [recognizer locationInView:recognizer.view];

    [imgView setCenter:CGPointMake(tapLocation.x,tapLocation.y)];     
    [imgView setUserInteractionEnabled:YES];
    UIPanGestureRecognizer *recognizer1 = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan1:)];
    [imgView addGestureRecognizer:recognizer1];
    [self.view addSubview:imgView];

}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self initImagesAndGesture];

    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addImgView:)];
    tapRecognizer.numberOfTapsRequired = 2;
    tapRecognizer.numberOfTouchesRequired = 1;
    [tapRecognizer setDelegate:self];
    self.view.userInteractionEnabled = YES;

    [self.view addGestureRecognizer:tapRecognizer];   
}
  • 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-04T19:31:33+00:00Added an answer on June 4, 2026 at 7:31 pm

    Just iterate through all subviews…

    // targetView is the one you are checking...
    - (BOOL)isViewIntersectingAnyOtherViews:(UIView*)targetView {
        for (UIView *view in self.view.subviews) {
            if (view == targetView) continue; // Don't check against your own view
            if (CGRectIntersectsRect(view, thisView)) {
                return YES;
            }
        }
        return NO;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button in a Nib based view which does not behave like
I am trying to add CSS3 based rounded corner support in IE7 and IE8
I want to add a javascript based chat system to my web app. I
Im trying to add and remove an input box based on when a box
How can I add the variable value to my text area based on the
How do I add an auto-refresh feature based on the value of a GET
I want to add an progress bar into my C# based application. I would
I'm trying to add international support for a website based on the Erlang Web
I want to add tracking to our Flash-based media player so that we can
I want to add a feature to a linux-based web service that allows untrusted

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.