国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS仿抖音視頻加載動畫效果的實現方法

2019-10-21 18:39:17
字體:
來源:轉載
供稿:網友

前言

這幾天一直跟開源的抖音demo斗智斗勇,今天跟大家分享的是抖音中或者快手中加載視頻動畫,這個加載效果還是挺實用,下面話不多說了,來隨著小編一起學習學習吧

上圖看成品

iOS,仿抖音,視頻,加載,動畫

實現原理

首先我創建一個視圖

@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]; //調用動畫代碼}

這里我們可以看到 我們實際上創建的是一個 1pt寬度 0.5 pt的寬度 的視圖

緊接著動畫實現的代碼

- (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; }}

完事 就這幾行代碼 搞定

其實核心的只有4行代碼

CABasicAnimation *scaleAnimation = [CABasicAnimation animation];scaleAnimation.keyPath = @"transform.scale.x";scaleAnimation.fromValue = @(1.0f);scaleAnimation.toValue = @(1.0f * ScreenWidth);

關鍵在scaleAnimation.keyPath = @"transform.scale.x"; 這里我們要沿著x做縮放

縮放的得值從 1~屏幕寬度, 當然值多大自己可以控制.

如果@"transform.scale.y" 則是沿著Y軸縮放

當然 如果寫成@"transform.scale" 那就X,Y 一起縮放 大家可以試試.

總結

本篇的動畫技巧是 縮放的 transform.scale.y 從一個點 做layer縮放 就會出現 加載效果.

最后附上demo

好了,以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網的支持。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 云梦县| 长武县| 贺州市| 蓬安县| 沿河| 左云县| 乌审旗| 伊通| 沙坪坝区| 栾川县| 泾源县| 鄂托克旗| 满城县| 邢台县| 伊金霍洛旗| 博白县| 望谟县| 长乐市| 岳普湖县| 扬中市| 金山区| 清水县| 德兴市| 澄城县| 凌源市| 崇州市| 沙雅县| 皋兰县| 离岛区| 玉溪市| 牟定县| 阿拉善右旗| 霍山县| 东平县| 凤冈县| 和龙市| 新邵县| 五台县| 桐柏县| 鄄城县| 土默特左旗|