Ideas:
1. Create a singleton
+ (instancetype) sharemanager { static ccpaomaview *pmodel = nil; Static dispatch_once_t once; Dispatch_once (&once, ^{ = [[Ccpaomaview alloc]initwithframe:cgrectmake (0 00.0468 *kscreenheight)]; }); return Pmodel;}
2. The received data in the local plist, does not apply to a large amount of data, each time the first data read, read to complete the deletion of the entire plist, and then the rest of the re-deposited into the plist
3. According to the animation agent, listen to the end of the animation execution, set the animation instance to nil
- (void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag{NSLog (@"%@", [Self.paomaLabel.layer Animationforkey:@"Paomadeng"]); if([Self.paomaLabel.layer Animationforkey:@"Paomadeng"] ==anim) { //removing the first set of data[_array Removeobjectatindex:0]; //Remove entire plist[Ccpaomamodel removepaomaplist]; //re-write[_array writetofile:[ccpaomamodel filename] atomically:yes]; //after the animation stops, set the instance to nil_pmaniamtion =Nil; //Remove the marquee after the array is empty if(_array.count >0) {[Self showPaomaView:self.superview]; }Else{Self.hidden=YES; [Self removefromsuperview]; } NSLog (@"%@", Self.array); }}
4. Determine if the animation instance is empty, so that the switch interface, the marquee continues, not to start again
- (void) Paomaaniamtion: (cgfloat) count{//to determine that an animation instance is not present, exists, or does not exist. if(_pmaniamtion = =Nil) {_pmaniamtion=[cabasicanimation animation]; _pmaniamtion.keypath=@"transform.translation.x"; CGFloat W=cgrectgetwidth (_paomalabel.bounds); _pmaniamtion.fromvalue=@ (W); _pmaniamtion.tovalue= @(-v); _pmaniamtion.duration=_anitime; _pmaniamtion.repeatcount=count; _pmaniamtion.removedoncompletion= NO;//animation end does not remove_pmaniamtion.fillmode = Kcafillmodeforwards;//the end of the animation will remain the end of the state_pmaniamtion.Delegate= self;//Set up proxy[_paomalabel.layer addanimation:_pmaniamtion Forkey:@"Paomadeng"]; }Else{_pmaniamtion.repeatcount=count; }}
5. Toggle the interface, pause, resume animation
#pragma mark-interface appears, disappears, creates, resumes, pauses animation-(void) viewwillappear: (BOOL) animated { [_paomaview ShowPaomaView:self.view]; [_paomaview resumeanimation];} -(void) viewwilldisappear: (BOOL) animated { [_paomaview pauseaniamtion];}
Don't talk much, GitHub see code
iOS Learning-22 Global Marquee