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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:33:09+00:00 2026-06-13T17:33:09+00:00

I want to simply have a loop so that an object continuously moves across

  • 0

I want to simply have a loop so that an object continuously moves across the screen at the bottom. Here is my code it should be pretty easy to understand.

@interface ViewController ()

@end

@implementation ViewController




    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [self performSelector:@selector(spawnRocket) withObject:self afterDelay:2]; //delay before the object moves

    }

    -(void)spawnRocket{
        UIImageView *rocket=[[UIImageView alloc]initWithFrame:CGRectMake(-25, 528, 25, 40)]; //places imageview right off screen to the bottom left
        rocket.backgroundColor=[UIColor grayColor];

        [UIView animateWithDuration:5 animations:^(){rocket.frame=CGRectMake(345, 528, 25, 40);} completion:^(BOOL finished){if (finished)[self spawnRocket];}]; //this should hopefully make it so the object loops when it gets at the end of the screen


    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    @end

After doing all this i click run and all i see is a white screen on my iphone 6.0 simulator

ps. im running xcode 4.5.1

  • 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-13T17:33:10+00:00Added an answer on June 13, 2026 at 5:33 pm

    A few things:

    1. UIImageView *rocket=[[UIImageView alloc]initWithFrame:...

      You’re not assigning an image to the image view, the best way to do this is to use:

      UIImage* image = [UIImage imageNamed:@"image.png"];
      UIImageView *rocket = [[UIImageView alloc] initWithImage:image];
      rocket.frame = CGRectMake(-25, 528, 25, 40);
      
    2. (The root cause of your problem) You are not adding your UIImageView to your main view, hence it’s not being displayed. In spawnRocket, you should do:

      [self.view addSubview:rocket];
      

      Note: Because you want this to be done in a loop, you’re gonna have to make sure your memory management is in order.

      I don’t know whether you still want the rocket on screen after it’s finished moving, but if not, remember to keep a reference to the UIImageView and removeFromSuperview when you’re done (to prevent memory leaks).

    3. Calling spawnRocket in viewDidLoad is probably not the best idea, it may not reach the screen yet when spawnRocket is called. Try calling it in viewWillAppear or viewDidAppear (whatever is best in your case)

    4. [self performSelector:@selector(spawnRocket) withObject:self afterDelay:2];

      You don’t need to provide self within withObject:, you’re not accepting any parameters within spawnRocket

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

Sidebar

Related Questions

I have several sql queries that I simply want to fire at the database.
I have an object that is dynamically created. Here's a simple example: global.data {
I have python code below that will loop through a table and print out
I have a simple bit of code that is filling a select object from
Hey guys I have an assigned array from mysql results and I simply want
I have three source files in a folder. I simply want to compile them
I have a blog on something.wordpress.com , I simply want one post to ALWAYS
I have an Activity which uses a Fragment . I simply want to pass
I have this variable: $timestamp = strftime(%Y-%m-%d %h:%M:%S %a, time ()); I simply want
I have a Master Page with nested pages in ASP.NET. Fairly simply I want

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.