Package Snowflake Drop Effect

Source: Internet
Author: User

As follows:

The code below, create a new view, so that he inherited UIView, which is used in Lzwsnowview;

#import "LzwSnowView.h"@interfaceLzwsnowview () {UIImage*_image;}@end@implementationLzwsnowview-(Instancetype) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {//Snowflake Pictures_image = [UIImage imagenamed:@"Snow"]; //loop to add a picture[Nstimer scheduledtimerwithtimeinterval:.8f target:self selector: @selector (addonesnowflake) Userinfo:nil Repe    Ats:yes]; }    returnSelf ;}- (void) addonesnowflake{//Snowflake PicturesUiimageview *IMGV =[[Uiimageview alloc]initwithimage:_image]; //randomly generate snowflake locations    intStartX = round (random ()% the); intEndX = round (random ()% the); //scale and speed of randomly generated snowflakes    DoubleScale =1/round (random ()% -) +1.0; DoubleSpeed =1/round (random ()% -) +1.0; //set the starting position of snowflakesImgv.frame = CGRectMake (StartX,- -, -. f * scale, -. f *Scale ); Imgv.alpha=. 5f; //Add snowflakes to view[self ADDSUBVIEW:IMGV];        [Self SENDSUBVIEWTOBACK:IMGV]; //Animate change Position[UIView animatewithduration: -* Speed animations:^{        //Curve[UIView setanimationcurve:uiviewanimationcurvelinear]; Imgv.frame= CGRectMake (EndX, +. F, -. f * scale, -. f *Scale ); } Completion:^(BOOL finished) {if(finished) {[IMGV Removefromsuperview];    }            }]; }@end

Add Lzwsnowview to the controller that needs to add snowflakes, as follows:

Lzwsnowview *SNOWV = [[Lzwsnowview alloc]initwithframe:self.view.bounds];    [Self.view ADDSUBVIEW:SNOWV];    [Self.view SENDSUBVIEWTOBACK:SNOWV];

Ok...

Encapsulate snowflake Drop effect

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.