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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:26:10+00:00 2026-05-26T03:26:10+00:00

I am trying to detect the collision between a falling/animated UIImageView that is created

  • 0

I am trying to detect the collision between a falling/animated UIImageView that is created every second with an NSTimer. Here’s the code:

-(void)newobject{

    int randomx = 76+ arc4random() %(290);
    int randomDuration = 2+ arc4random() %(6);
    int randomImage = 1+ arc4random() %(3) ;

    NewObject = [[UIImageView alloc] initWithFrame:CGRectMake(randomx,0,36 ,36)];        
    UIImage *imag = [UIImage imageNamed:@"ball.png"];
    [NewObject setImage:imag];
    [self.view addSubview:NewObject];

    numberofObjects += 1;
    NewObject.tag = numberofObjects;

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:randomDuration];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDone:finished:context:)];
    NewObject.frame = CGRectMake(randomx, 300,NewObject.frame.size.width,NewObject.frame.size.height);

    [UIView commitAnimations];
}

That code crates a new UIImageView with the name NewObject and animates it down the screen. To detect the collision I have another NSTimer that is called every 1.0/60. Here’s the code:

-(void)Collison{

    for (int i = 1; i < numberofObjects; i++) {
        UIImageView *image = NewObject;

        [image viewWithTag:i];
        CALayer *layer = image.layer.presentationLayer;
        CGRect NewObjectFrame =  layer.frame;
        CALayer *layer2 = Sprint.layer.presentationLayer;
        CGRect SprintFrame = layer2.frame;

        if (CGRectIntersectsRect(NewObjectFrame, SprintFrame)) {
            [self StopTimers];

            NSLog(@"hello");
        }
    }
}

The problem is that the console says “It works” but the UIImage didn’t collide and I can collide the character with the image but the console says nothing and at the same time if I try to collide the character with the UIImageView it works. What i’am trying to say is that it’s not reliable. Can someone help?

update: I edited the code but now it detecting the last uiimageview that is added.

  • 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-26T03:26:11+00:00Added an answer on May 26, 2026 at 3:26 am

    ok well i got it. It’s simple so all you need to do is make an NSMutableArray and check the array for collision with a for loop.

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

Sidebar

Related Questions

I am trying to detect which web in sharepoint that the user is looking
I'm trying to detect the compiler used to compile my source code. I can
I'm trying to detect overlap between elements on my canvas. The attempt is to
I am trying to detect the collision from two objects. This collision has more
i am trying to detect Collision of two sprites in the following way...but when
I am trying to detect collisions in cocos2D. I am using this code: -
I'm trying to use collision detection to detect when my mouse hits an image
I am trying to detect the browser in my C# code by comparing the
I'm trying to detect an occurrence of a string within string. But the code
In trying to detect a right mouse click with jquery, I noticed that the

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.