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