178 achieve snow-flying effect

Source: Internet
Author: User

The effect is as follows:

ViewController.h

1 #import <UIKit/UIKit.h>23@interface  viewcontroller: Uiviewcontroller4 @property (Strong, Nonatomic) UIImage *Imgsnowflake; 5 6 @end

Viewcontroller.m

1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4- (void) Layoutui;5- (void) Snow;6 @end7 8 @implementationViewcontroller9 #defineKapplicationframe [[UIScreen mainscreen] applicationframe]Ten #defineKwidthofsnowflake 30.0 One  A- (void) Viewdidload { - [Super Viewdidload]; -      the [self layoutui]; - } -  -- (void) didreceivememorywarning { + [Super didreceivememorywarning]; -     //Dispose of any resources the can be recreated. + } A  at- (void) Layoutui { -Self.view.backgroundColor = [Uicolor colorwithred:0.218Green0.219Blue0.196Alpha1.000]; -_imgsnowflake = [UIImage imagenamed:@"Snowflake"]; -      -     //timer, executed every 0.5 seconds -[Nstimer Scheduledtimerwithtimeinterval:0.5 in target:self - selector: @selector (Snow) to Userinfo:nil + Repeats:yes]; - } the  *- (void) Snow { $NSString *strwidthofscene = [NSString stringWithFormat:@"%f", kapplicationframe.size.width-Kwidthofsnowflake];Panax NotoginsengCGFloat StartX = Arc4random ()%[strwidthofscene IntegerValue];//generate random number 0 to strWidthOfScene-1 -CGFloat endx = arc4random ()% ([Strwidthofscene integervalue]+1);//generate random number 1 to Strwidthofscene the      +Uiimageview *IMGV =[[Uiimageview alloc] initwithimage:_imgsnowflake]; AImgv.frame = CGRectMake (StartX,-20.0, Kwidthofsnowflake, kwidthofsnowflake); theImgv.alpha =0.8; + [Self.view ADDSUBVIEW:IMGV]; -      $ [UIView Beginanimations:nil context:null]; $[UIView setanimationduration:5]; -Imgv.frame =CGRectMake (EndX, -kapplicationframe.size.height+20.0-Kwidthofsnowflake, the Kwidthofsnowflake, - kwidthofsnowflake);Wuyi [UIView commitanimations]; the } -  Wu @end

178 achieve snow-flying 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.