ios--Timer Example: Flash Sparkle (animation)

Source: Internet
Author: User

Animations implemented in this example: UIView timer disappears and then flashes, a flash of animation

Technology used: Timer (Nstimer) + animation (beginanimations/commitanimations)

Specific implementation steps:

The first step: the timer section is completely copied the previous example: http://blog.csdn.net/wanggsx918/article/details/38269919

1. Define a variable and a method in the. h file:

@interface xxxviewcontroller:uiviewcontroller{    nstimer *showtimer;//Timer Variable}//The method to execute-(void) Handlescrolltimer: ( Nstimer *) Thetimer;     -(void) Starttimer;

2. Open and close timers in. m files, and bind method:

-(void) Viewdidappear: (BOOL) animated  {/    //re-open the timer when the page is displayed    [Showtimer setfiredate:[nsdate Distantpast]];} -(void) starttimer{    //define Time Counter: Execute Handlescrolltimer method every 2 seconds    showtimer = [Nstimer scheduledtimerwithtimeinterval:2.0                                                 target:self                                               selector: @selector (handlescrolltimer:)                                               Userinfo:nil                                                Repeats:true];    [[Nsrunloop Currentrunloop] Addtimer:showtimer formode:nsdefaultrunloopmode];} When the page disappears, execute-(void) Viewdiddisappear: (BOOL) animated{    //off timer    [Showtimer setfiredate:[nsdate Distantfuture]];}

3. Start the timer:

    Open Thread    [self performselectoronmainthread: @selector (Starttimer) Withobject:nil Waituntildone:yes];



Step Two: Animation section

Write the animation code in the Handlescolltimer: method:

-(void) Handlescrolltimer: (Nstimer *) thetimer{    Scanline.alpha = 1.0;    [UIView beginanimations:@ "Scanline" context:nil];    [UIView setanimationduration:0.8];    [UIView setanimationcurve:uiviewanimationcurvelinear];    Scanline.alpha = 0.05;    [UIView commitanimations];}


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.