iOS仿抖音視頻加載動(dòng)畫效果的實(shí)現(xiàn)方法
前言
這幾天一直跟開源的抖音demo斗智斗勇,今天跟大家分享的是抖音中或者快手中加載視頻的動(dòng)畫,這個(gè)加載效果還是挺實(shí)用,下面話不多說了,來隨著小編一起學(xué)習(xí)學(xué)習(xí)吧
上圖看成品
實(shí)現(xiàn)原理
首先我創(chuàng)建一個(gè)視圖
@interface ViewController () @property (nonatomic, strong) UIView *playLoadingView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //init player status bar self.playLoadingView = [[UIView alloc]init]; self.playLoadingView.backgroundColor = [UIColor whiteColor]; [self.playLoadingView setHidden:YES]; [self.view addSubview:self.playLoadingView]; //make constraintes [self.playLoadingView mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(self.view); make.width.mas_equalTo(1.0f); //寬 1 dp make.height.mas_equalTo(0.5f); //高 0.5 dp }]; [self startLoadingPlayAnimation:YES]; //調(diào)用動(dòng)畫代碼 }
這里我們可以看到 我們實(shí)際上創(chuàng)建的是一個(gè) 1pt寬度 0.5 pt的寬度 的視圖
緊接著動(dòng)畫實(shí)現(xiàn)的代碼
- (void)startLoadingPlayAnimation:(BOOL)isStart { if (isStart) { self.playLoadingView.backgroundColor = [UIColor whiteColor]; self.playLoadingView.hidden = NO; [self.playLoadingView.layer removeAllAnimations]; CAAnimationGroup *animationGroup = [[CAAnimationGroup alloc] init]; animationGroup.duration = 0.5; animationGroup.beginTime = CACurrentMediaTime() + 0.5; animationGroup.repeatCount = MAXFLOAT; animationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; CABasicAnimation *scaleAnimation = [CABasicAnimation animation]; scaleAnimation.keyPath = @"transform.scale.x"; scaleAnimation.fromValue = @(1.0f); scaleAnimation.toValue = @(1.0f * ScreenWidth); CABasicAnimation *alphaAnimation = [CABasicAnimation animation]; alphaAnimation.keyPath = @"opacity"; alphaAnimation.fromValue = @(1.0f); alphaAnimation.toValue = @(0.5f); [animationGroup setAnimations:@[scaleAnimation, alphaAnimation]]; [self.playLoadingView.layer addAnimation:animationGroup forKey:nil]; } else { [self.playLoadingView.layer removeAllAnimations]; self.playLoadingView.hidden = YES; } }
完事 就這幾行代碼 搞定
其實(shí)核心的只有4行代碼
CABasicAnimation *scaleAnimation = [CABasicAnimation animation]; scaleAnimation.keyPath = @"transform.scale.x"; scaleAnimation.fromValue = @(1.0f); scaleAnimation.toValue = @(1.0f * ScreenWidth);
關(guān)鍵在scaleAnimation.keyPath = @"transform.scale.x";
這里我們要沿著x做縮放
縮放的得值從 1~屏幕寬度, 當(dāng)然值多大自己可以控制.
如果@"transform.scale.y"
則是沿著Y軸縮放
當(dāng)然 如果寫成@"transform.scale"
那就X,Y 一起縮放 大家可以試試.
總結(jié)
本篇的動(dòng)畫技巧是 縮放的 transform.scale.y
從一個(gè)點(diǎn) 做layer縮放 就會(huì)出現(xiàn) 加載效果.
好了,以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
- iOS實(shí)現(xiàn)抖音點(diǎn)贊動(dòng)畫效果
- iOS實(shí)現(xiàn)點(diǎn)贊動(dòng)畫特效
- iOS仿AirPods彈出動(dòng)畫
- iOS自定義轉(zhuǎn)場動(dòng)畫的幾種情況
- iOS自定義UIButton點(diǎn)擊動(dòng)畫特效
- iOS基于CATransition實(shí)現(xiàn)翻頁、旋轉(zhuǎn)等動(dòng)畫效果
- iOS實(shí)現(xiàn)轉(zhuǎn)場動(dòng)畫的3種方法示例
- iOS實(shí)現(xiàn)數(shù)字倍數(shù)動(dòng)畫效果
- iOS如何優(yōu)雅地實(shí)現(xiàn)序列動(dòng)畫詳解
- iOS仿微博導(dǎo)航欄動(dòng)畫(CoreGraphics)的實(shí)現(xiàn)方法
- 詳解 iOS 系統(tǒng)中的視圖動(dòng)畫
相關(guān)文章
iOS仿微博導(dǎo)航欄動(dòng)畫(CoreGraphics)的實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于iOS仿微博導(dǎo)航欄動(dòng)畫(CoreGraphics)的實(shí)現(xiàn)方法,文章最后給出了完整的示例代碼,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07iOS利用余弦函數(shù)實(shí)現(xiàn)卡片瀏覽工具
這篇文章主要為大家詳細(xì)介紹了iOS利用余弦函數(shù)實(shí)現(xiàn)卡片瀏覽工具,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04iOS開發(fā)之tableView cell的展開收回功能實(shí)現(xiàn)代碼
本文介紹了iOS開發(fā)之tableView cell的展開收回功能實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01詳解Xcode 9 設(shè)置 iOS無線真機(jī)調(diào)試
本篇文章主要介紹了詳解Xcode 9 設(shè)置 iOS無線真機(jī)調(diào)試,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-12-12iOS實(shí)現(xiàn)步驟進(jìn)度條功能實(shí)例代碼
這篇文章主要給大家介紹了關(guān)于iOS實(shí)現(xiàn)步驟進(jìn)度條功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11iOS使用GCDSocketManager實(shí)現(xiàn)長連接的方法
下面想就為大家分享一篇iOS使用GCDSocketManager實(shí)現(xiàn)長連接的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12