本文實例為年夜家分享了IOS全局賽馬燈制造辦法,供年夜家參考,詳細內容以下
思緒:
1.創立一個單例
+ (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.把吸收的數據存在當地的 plist,不實用於年夜量數據,每次讀取第一個數據,讀取完成刪除全部 plist,再把剩下的從新存進 plist
3.依據動畫署理,監聽動畫履行停止,將動畫實例置為 nil
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ NSLog(@"%@",[self.paomaLabel.layer animationForKey:@"paoMaDeng"]); if ([self.paomaLabel.layer animationForKey:@"paoMaDeng"] == anim) { //移除第一組數據 [_array removeObjectAtIndex:0]; //移除全部 plist [CCPaomaModel removePaomaPlist]; //從新寫入 [_array writeToFile:[CCPaomaModel filename] atomically:YES]; //動畫停滯以後,將實例置為 nil _pmAniamtion = nil; //數組為空以後移除賽馬燈 if (_array.count > 0) { [self showPaomaView:self.superview]; }else{ self.hidden = YES; [self removeFromSuperview]; } NSLog(@"%@",self.array); } }
4.斷定動畫實例能否為空,使得切換界面,賽馬燈持續,而不是從新開端
- (void)paomaAniamtion:(CGFloat)count{ //斷定動畫實例存不存在,存在持續,不存期近創立 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; //動畫停止不移除 _pmAniamtion.fillMode = kCAFillModeForwards; //動畫停止會堅持停止的狀況 _pmAniamtion.delegate = self; //設置署理 [_paomaLabel.layer addAnimation:_pmAniamtion forKey:@"paoMaDeng"]; }else{ _pmAniamtion.repeatCount = count; } }
5.切換界面,暫停、恢復動畫
#pragma mark -- 界面湧現、消逝,創立、恢復、暫停動畫 - (void)viewWillAppear:(BOOL)animated { [_paomaView showPaomaView:self.view]; [_paomaView resumeAnimation]; } - (void)viewWillDisappear:(BOOL)animated { [_paomaView pauseAniamtion]; }
話不多說,github 見代碼
以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐本站。
【進修iOS全局賽馬燈】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!