Method one: Using Nsmutablearray to achieve
Nsmutable *array; Global variables, called with timers in. m files
-(void) down{ static int jiange = 0; jiange++; if (Jiange > 2) { jiange = 0; [Self snowstate]; } [Self snowdown];} -(void) snowstate{for (int i = 0; i < [array count]; i++) { Myimageview *img = [Array objectatindex:i];
if (Img.tag = = 0) { img.tag = 1; [Self.view addsubview:img]; break;//extract Snowflake } }}-(void) snowdown{for (int i = 0; i < [array count]; i++) { Myimageview *img = [a Rray objectatindex:i]; if (Img.tag = = 1) { img.center = Cgpointmake (img.center.x, img.center.y+10); if (Img.center.y > 480+25) { Img.tag = 0; Img.center = Cgpointmake (Arc4random ()%370-50, -50);}}}
Method Two: Using frame animation
Call with Timer
viewcontroller.m-(void) snowdown{//animation effect Uiimageview *iv = [[Uiimageview alloc]init]; int a = Arc4random ()%51;//snowflake size random (0~50) iv.frame = CGRectMake (Arc4random ()%370-50, -50, A, a); Iv.image = [UIImage imagenamed:@ "Flake"]; [Self.view Addsubview:iv]; [UIView Beginanimations:nil context: (__bridge void *) (iv)]; [UIView Setanimationduration:5]; [UIView setanimationdelegate:self]; [UIView setanimationdidstopselector: @selector (animationDidStop:finished:context:)]; Iv.frame = CGRectMake (Arc4random ()%370-50, A, a); [UIView commitanimations];} -(void) Animationdidstop: (NSString *) Animationid finished: (NSNumber *) finished context: (void *) context//to bottom elimination { Uiimageview *image = (__bridge Uiimageview *) context; [Image Removefromsuperview];}
Frame animation than with Nsmutablearray to be concise, easy to understand
Learning practice--ios snow falling in the implementation of the method