Clock Animation in iOS

Source: Internet
Author: User

IOS animation effect is very much, we may encounter many animation effects in development, we will use the core animation frame coreanimation, the core animation has a lot of animation effect, Are all inside the quartzcore.framework frame, today we look at its only one cadisplaylink use, and complete a snowflake effect:

  As follows:

1. Introduction of the framework

  2. Introduction of header File

The main feature of Cadisplaylink is the ability to provide a periodic call to the selector that we assign to it, which, from this point of view, is much like a timer nstimer.

Cadisplaylink is a timer class that allows us to draw specific content to the screen at a frequency that is synchronized with the screen refresh rate. Once the Cadisplaylink is registered to Runloop in a specific mode, Runloop sends a specified selector message to the target specified by Cadisplaylink whenever the screen displays the end of the content refresh. The corresponding selector of the Cadisplaylink class is called once.

After the Nstimer is registered with the Runloop in the specified mode, Runloop sends a specified selector message to the specified target whenever the set cycle time arrives.

3 Declaring member variables

  @interface   Viewcontroller ()  /*   definition Object *  */  @property (nonatomic,strong) cadisplaylink  * link;  /*   Defines the number of times an integer index is used to control execution *  */  @property (nonatomic,assign) Nsinteger index;  /*   Set the picture to display *  */  @property (nonatomic,strong) UIImage  * image;   @end  

4, Initialize a member variable

-(void  ) viewdidload {[Super viewdidload];  //  initialize picture  Self.image=[uiimage Imagenamed:@ "  " ";    Self.view.backgroundColor  =[uicolor Blackcolor];  //  Initialize clock animation  Self.link=[cadisplaylink displaylinkwithtarget:self selector: @selector (show)];      //  add to main loop  

  5. Animation execution produces snowflakes

#pragmaMark-Show Snowflakes-(void) show{//the clock executes approximately 60 times per second, and we need to control the display of 10 flakes per second    if(self.index%6==0) {                //size of random snowflakesNsinteger r= Arc4random_uniform ( -)+Ten; Uiimageview* Imageview=[[uiimageview Alloc]initwithframe:cgrectmake (Arc4random_uniform (375), -R, R , R)]; Imageview.image=Self.image;        [Self.view Addsubview:imageview]; //animation changes the location of snowflakes[UIView Animatewithduration:arc4random_uniform (3)+7animations:^{imageview.frame=cgrectmake (Arc4random_uniform (375),667+arc4random_uniform ( the), R, R); //change the transparency of snowflakesImageview.alpha=0.3; //Make snowflakes Spinimageview.transform=cgaffinetransformmakerotation (M_PI); } Completion:^(BOOL finished) {//Be sure to remove snowflakes after you finish[ImageView Removefromsuperview];        }]; } Self.index++;}

Jerry Education
Source:http://www.cnblogs.com/jerehedu/
Copyright Notice: The copyright of this article belongs to cigarettes DeskJerry EducationSectionTechnology Co., Ltd. and blog Park are shared, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.
Technical Consultation:

Clock Animation in iOS

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.