The realization method of--ios snow falling in learning practice

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.