iOS仿抖音视频加载动画效果的实现方法

前言

公司主营业务:网站制作、做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出龙泉驿免费做网站回馈大家。

这几天一直跟开源的抖音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 (本地下载)

好了,以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对创新互联的支持。

当前名称:iOS仿抖音视频加载动画效果的实现方法
文章路径:https://www.cdcxhl.com/article44/gdpehe.html

成都网站建设公司_创新互联,为您提供用户体验App设计网站设计公司品牌网站建设外贸网站建设电子商务

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设公司