This article shares the method of making iOS global marionettes for your reference. The specific content is as follows
Ideas:
1. Create a single case
+ (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. The received data is stored in the local plist, which is not suitable for a large amount of data. Each time the first data is read, the entire plist is deleted after reading, and the rest is re-stored into the plist.
3. According to the animation agent, the monitoring animation execution is completed and the animation instance is set to nil
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ NSLog(@"%@",[ animationForKey:@"paoMaDeng"]); if ([ animationForKey:@"paoMaDeng"] == anim) { //Remove the first set of data [_array removeObjectAtIndex:0]; //Remove the entire plist [CCPaomaModel removePaomaPlist]; //Rewrite [_array writeToFile:[CCPaomaModel filename] atomically:YES]; //After the animation stops, set the instance to nil _pmAniamtion = nil; //Remove the horse-drawn after the array is empty if (_array.count > 0) { [self showPaomaView:]; }else{ = YES; [self removeFromSuperview]; } NSLog(@"%@",); } }
4. Determine whether the animation instance is empty, so that the interface is switched, the marquee continues, rather than starting again
- (void)paomaAniamtion:(CGFloat)count{ //Judge whether the animation instance exists or not, it will continue, and if it does not exist, it will be created if (_pmAniamtion == nil) { _pmAniamtion = [CABasicAnimation animation]; _pmAniamtion.keyPath = @""; CGFloat W = CGRectGetWidth(_paomaLabel.bounds); _pmAniamtion.fromValue = @(W); _pmAniamtion.toValue = @(-W); _pmAniamtion.duration = _aniTime; _pmAniamtion.repeatCount = count; _pmAniamtion.removedOnCompletion = NO; //The animation ends without removal _pmAniamtion.fillMode = kCAFillModeForwards; //The end of the animation will remain in the end state _pmAniamtion.delegate = self; //Set the proxy [_paomaLabel.layer addAnimation:_pmAniamtion forKey:@"paoMaDeng"]; }else{ _pmAniamtion.repeatCount = count; } }
5. Switch the interface, pause and restore animation
#pragma mark -- The interface appears and disappears, create, restore, and pause animations- (void)viewWillAppear:(BOOL)animated { [_paomaView showPaomaView:]; [_paomaView resumeAnimation]; } - (void)viewWillDisappear:(BOOL)animated { [_paomaView pauseAniamtion]; }
Without further ado, see you on githubCode
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.