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];}