如何使用iOS仿抖音視頻加載動(dòng)畫(huà)效果-創(chuàng)新互聯(lián)

小編給大家分享一下如何使用iOS仿抖音視頻加載動(dòng)畫(huà)效果,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

創(chuàng)新互聯(lián)-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性?xún)r(jià)比本溪網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式本溪網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋本溪地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴(lài)。

實(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)畫(huà)代碼}

這里我們可以看到 我們實(shí)際上創(chuàng)建的是一個(gè) 1pt寬度 0.5 pt的寬度 的視圖

緊接著動(dòng)畫(huà)實(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)然 如果寫(xiě)成@"transform.scale"那就X,Y 一起縮放 大家可以試試.

以上是“如何使用iOS仿抖音視頻加載動(dòng)畫(huà)效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

當(dāng)前名稱(chēng):如何使用iOS仿抖音視頻加載動(dòng)畫(huà)效果-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://muchs.cn/article22/coiscc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)用戶(hù)體驗(yàn)、網(wǎng)站維護(hù)、建站公司、軟件開(kāi)發(fā)、網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開(kāi)發(fā)公司