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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:12:46+00:00 2026-05-18T21:12:46+00:00

With full compliments, may I start by declaring that I am new to iPhone

  • 0

With full compliments, may I start by declaring that I am new to iPhone programming. Thus I will like to ask for help on the solution on how to implement an animation where “a” ball falls randomly from the top of the iPhone screen. The ball’s attribute is such that it has different sizes, speed and can bounce too i.e there is collision also involved.

I am trying to use just an image of the ball and I added the ball image through Interface Builder(IB) and connected the UIImageView to files owner in IB and I have been trying without success to access the image programatically by adding the IBOutlet keyword to the .h file(please see the .h and .m code below).
When I run the code all I get is the image appearing and instantly disappearing. how do I get this ball to fall randomly with some bounce or collision.

To be precise I wish to have the kind of animation such as that obtained in the iPhone game falling balls…where the balls fall and still bounce off.

Thanks in advance for your help
CHEERS!!

***The .h file***

@interface TestBallsViewController : UIViewController {

  IBOutlet UIImageView *ball;

 CGPoint ballMovement;

 double size;
 double speed;

}


@property(nonatomic, retain)IBOutlet UIImageView *ball;


- (void)initializeTimer;


- (void)animateBall:(NSTimer *)theTimer;



**The .m file**

@implementation TestBallsViewController

@synthesize ball;


- (void)dealloc {

 [ball release];

    [super dealloc];
}



- (void)viewDidLoad {
 [super viewDidLoad];
 ballMovement = CGPointMake(2,2);  
 [self initializeTimer];

}



- (void)initializeTimer
 { 
  float theInterval = 0.3;

  [NSTimer scheduledTimerWithTimeInterval:theInterval target:self

                   selector:@selector(animateBall:) userInfo:nil repeats:YES];
}



- (void)animateBall:(NSTimer *)theTimer

 {
  ball.center = CGPointMake(ball.center.x+ballMovement.x, 
                                                       ball.center.y+ballMovement.y);


     int startX =arc4random()%100;
                   int endX = arc4random()%320; 
     ball.frame= CGRectMake(startX, -100, 15.0 * size, 15 * size);
                   ball.frame = CGRectMake(endX, 480, 15.0 * size, 15.0 * size);



  if(ball.center.x > 300 || ball.center.x < 20) ballMovement.x = 
                                                                     - ballMovement.x;
  if(ball.center.y > 440 || ball.center.y < 40) ballMovement.y =
                                                                     - ballMovement.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-05-18T21:12:46+00:00Added an answer on May 18, 2026 at 9:12 pm
    - (void)animateBall:(NSTimer *)theTimer
    
     {
      [UIView beginAnimations:nil context:nil];
      [UIView setAnimationDuration:1.0];
      ball.center = CGPointMake(ball.center.x+ballMovement.x, 
                                                           ball.center.y+ballMovement.y);
    
    
         int startX =arc4random()%100;
                       int endX = arc4random()%320; 
         ball.frame= CGRectMake(startX, -100, 15.0 * size, 15 * size);
                       ball.frame = CGRectMake(endX, 480, 15.0 * size, 15.0 * size);
    
    
    
      if(ball.center.x > 300 || ball.center.x < 20) ballMovement.x = 
                                                                         - ballMovement.x;
      if(ball.center.y > 440 || ball.center.y < 40) ballMovement.y =
                                                                         - ballMovement.y;
      [UIView commitAnimations];
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Full disclosure, I'm new to Visual Studio Web Tests and coding for them. I've
How full-screen mode, like in web browsers, for application running under Windows OS is
The full message that I got on the console is: Invalid memory access of
Full edit: The scenario is that after uploading the file to the server via
Full Tilt Poker's GUI has a box of text that keeps reporting on the
I have a folder full of zipped files (about 200). I would like to
Besides full-text indexing and using LIKE keyword, what are other tools to build search
Full Disclosure: I am bad at javascript. I'm trying to write something that takes
full explanation: I'm working on a project to generate twitter links that post over
Full Program: Option Strict On : Option Explicit On Module Module1 Sub Main() 'System.Diagnostics.Debug.Listeners.Add(New

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.