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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:16:32+00:00 2026-06-17T04:16:32+00:00

I would like to know how this app stacks up uiimage and wavering in

  • 0

I would like to know how this app stacks up uiimage and wavering in UIKit.

I’m following this xcode: Using a UIImageView subclass with NSTimers
to have images dropping down in random, but how do I catch it and stack the UIImage together ?

enter image description here

Thanks for the reply… EDIT: for clarity

https://www.youtube.com/watch?v=2dpZCoi4xFk 40sec onwards will show how it stack on top each other and swing with accerometer

This will emulate the dropping of UIIimageView

- (void)viewDidLoad {
    [super viewDidLoad];

    // set the background color to something COLD
    self.view.backgroundColor = [UIColor colorWithRed:0.0 green:0.5 blue:1.0 alpha:1.0];

    // load our ph image we will use the same image over and over
    phImage = [UIImage imageNamed:@"placeholder.png"];

    // start a timet that will fire 1 times per second
    [NSTimer scheduledTimerWithTimeInterval:(1) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}

// Timer event is called whenever the timer fires
- (void)onTimer
{
    // build a view from our ph image
    UIImageView* placeholderView = [[UIImageView alloc] initWithImage:phImage];

    // use the random() function to randomize up our ph attributes
    //int startX = round(random() % 300);
    int startX = round(random() % 275);
    //int endX = round(random() % 300);
    int endX = startX;

    double scale = 1 / round(random() % 100) + 1.0;
    double speed = 1 / round(random() % 50) + 1.0;

    // set the PH start position
    phView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
    phView.alpha = 0.25;

    // put the ph in our main view
    [self.view addSubview:phView];

    [UIView beginAnimations:nil context:phView];
    // set up how fast the ph will fall
    [UIView setAnimationDuration:5 * speed];

    // set the postion where ph will move to
    phView.frame = CGRectMake(endX, 500.0, 25.0 * scale, 25.0 * scale);

    // set a stop callback so we can cleanup the ph when it reaches the
    // end of its animation
    [UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
    [UIView setAnimationDelegate:self];
    [UIView commitAnimations];

}
- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

    UIImageView *phView = context;
    [phView removeFromSuperview];
    NSLog(@"[phView retainCount] = %d",[phView retainCount]);

}

Thanks for reading and commenting.

  • 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-17T04:16:33+00:00Added an answer on June 17, 2026 at 4:16 am

    For stacking, just make a UIView that holds all the placed images together.

    UIView *stackView = [UIView new];
    
    -(void) addView: (UIView*) view toStack: (UIView*) stackView
    {
    
        if ([stackView subviews].count > 0)
        {
            CGRect frame = [[[stackView subviews] lastObject] frame];
            view.frame = CGRectOffset(frame, 0, 20);
        }
        [stackView addSubview:view];
    }
    

    For tilting, set up an accelerometer and use the x and y to determine the tilt.

    -(void)configureAccelerometer
    {
        UIAccelerometer*  theAccelerometer = [UIAccelerometer sharedAccelerometer];
        theAccelerometer.updateInterval = 0.20;
    
        theAccelerometer.delegate = self;
        // Delegate events begin immediately.
    }
    
    - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
    {
        UIAccelerationValue x, y, z;
        x = acceleration.x;
        y = acceleration.y;
    
        //[stackView tiltForX: x Y: y]
    
    }
    

    More info on Motion Events

    For the collision detection, you can probably do something like

    if (CGRectIntersectsRect([[[stackView subviews] lastObject] frame], fallingView.frame))
        [self addView: fallingView toStack: stackView];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how this homepage from Google Docs app is build
I would like to know if this method of setting up routing in Zend
I would like to know whether this is actually possible in Android? When Android
I would like to know what is this little icon called? And how to
I know this is very basic. I would like to use jQuery to change
I would like to split a line into words. I know this can be
I know this is stupid, but how would I do this? I would like
I know this is a weird question to ask, but I would like to
I would like to animate things in 3D space. I know this is possible
I would like to know how to write this inside my hittest if statement:

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.