IOS learning and ios learning routes
Ideas:
1. Create a singleton
+ (instancetype)shareManager { static CCPaomaView *pModel = nil; static dispatch_once_t once; dispatch_once(&once, ^{ pModel = [[CCPaomaView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.0468 *KScreenHeight)]; }); return pModel;}
2. Store the received data in a local plist, which is not applicable to a large amount of data. Each time the first data is read, the entire plist is read and deleted, and the remaining data is resaved to the plist.
3. Listen to the animation execution end based on the animation proxy and 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) {// remove the first group of data [_ array removeObjectAtIndex: 0]; // remove the entire plist [CCPaomaModel removePaomaPlist]; // re-write [_ array writeToFile: [CCPaomaModel filename] atomically: YES]; // After the animation is stopped, set the instance to nil _ pmAniamtion = nil; // if (_ array. count> 0) {[self showPaomaView: self. superview];} else {self. hidden = YES; [self removeFromSuperview];} NSLog (@ "% @", self. array );}}
4. Determine whether the animation instance is empty, so that you can switch the interface and run the Trojan to continue, rather than start again.
-(Void) paomaAniamtion :( CGFloat) count {// judge whether the animation instance exists or persists. if (_ pmAniamtion = nil) {_ pmAniamtion = [CABasicAnimation animation]; _ pmAniamtion. keyPath = @ "transform. translation. x "; CGFloat W = CGRectGetWidth (_ paomaLabel. bounds); _ pmAniamtion. fromValue = @ (W); _ pmAniamtion. toValue = @ (-W); _ pmAniamtion. duration = _ aniTime; _ pmAniamtion. repeatCount = count; _ pmAniamtion. removedOnCompletion = NO; // The animation ends without removing _ pmAniamtion. fillMode = kCAFillModeForwards; // The animation ends at the end of the animation. delegate = self; // sets the proxy [_ paomaLabel. layer addAnimation: _ pmAniamtion forKey: @ "paoMaDeng"];} else {_ pmAniamtion. repeatCount = count ;}}
5. Switch the page to pause and resume the animation.
# Pragma mark-the interface appears and disappears, creates, restores, and pauses an animation-(void) viewWillAppear :( BOOL) animated {[_ paomaView showPaomaView: self. view]; [_ paomaView resumeAnimation];}-(void) viewWillDisappear :( BOOL) animated {[_ paomaView pauseAniamtion];}
For more information, see the code on github.