Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do I stack the UIImage together and wavering or swing in UIKit
    primarykey
    data
    text
    <p>I would like to know how this app stacks up uiimage and wavering in UIKit.</p> <p>I'm following this <a href="https://stackoverflow.com/questions/13589392/xcode-using-a-uiimageview-subclass-with-nstimers">xcode: Using a UIImageView subclass with NSTimers</a> to have images dropping down in random, but how do I catch it and stack the UIImage together ?</p> <p><img src="https://i.stack.imgur.com/p0pax.jpg" alt="enter image description here"></p> <p>Thanks for the reply... EDIT: for clarity</p> <p><a href="https://www.youtube.com/watch?v=2dpZCoi4xFk" rel="nofollow noreferrer">https://www.youtube.com/watch?v=2dpZCoi4xFk</a> 40sec onwards will show how it stack on top each other and swing with accerometer</p> <p>This will emulate the dropping of UIIimageView</p> <pre><code>- (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]); } </code></pre> <p>Thanks for reading and commenting.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload