html5点赞仿抖音,iOS仿抖音—加载点赞动画效果

本文介绍了如何使用iOS实现仿抖音的四种动画效果:数据加载动画、视频加载动画、红心点赞动画和双击点赞动画。详细讨论了每种动画的实现原理和关键代码,提供了一个全面的iOS仿抖音动画实现示例。
摘要由CSDN通过智能技术生成

iOS仿抖音短视频

前言

前段时间比较忙,最近终于有时间就继续对仿抖音的demo进行更新,本次更新的主要是抖音上的几种动画,下面先来看下效果图:

a5f08098efb0

抖音

说明

经过观察发现抖音主要要以下几种动画效果:

1、数据加载动画(两个小球来回切换)

2、视频加载动画(直线向两边扩散)

3、红心点赞动画(红心由小变大并向四周扩散)

4、双击点赞动画(多个红心由小变大并逐渐消失)

于是在经过各种资料查找及自我实践中完成了这四种动画,下面就这几种动画做一下简单说明

1、数据加载动画

a5f08098efb0

数据加载

这个动画大致观察发现是一个红球一个绿球左右来回切换实现的,但仔细观察你会发现,在左右切换的过程中有个黑色小球在不断变大缩小,跟随最上面的球运动。

因此我们需要添加三个小球,绿球、红球、黑球,默认绿球在左红球在右,黑球在绿球上

self.containerView = [[UIView alloc] init];

self.containerView.center = self.center;

self.containerView.bounds = CGRectMake(0, 0, 2.1f * kBallWidth, 2.0f * kBallWidth);

[self addSubview:self.containerView];

// 绿球

self.greenBall = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBallWidth, kBallWidth)];

self.greenBall.center = CGPointMake(kBallWidth * 0.5f, self.containerView.bounds.size.height * 0.5f);

self.greenBall.layer.cornerRadius = kBallWidth * 0.5f;

self.greenBall.layer.masksToBounds = YES;

self.greenBall.backgroundColor = GKColorRGB(35, 246, 235);

[self.containerView addSubview:self.greenBall];

// 红球

self.redBall = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBallWidth, kBallWidth)];

self.redBall.center = CGPointMake(self.containerView.bounds.size.width - kBallWidth * 0.5f, self.containerView.bounds.size.height * 0.5f);

self.redBall.layer.cornerRadius = kBallWidth * 0.5f;

self.redBall.layer.masksToBounds = YES;

self.redBall.backgroundColor = GKColorRGB(255, 46, 86);

[self.containerView addSubview:self.redBall];

// 黑球

// 第一次动画是正向,绿球在上,红球在下,阴影显示在绿球上

self.blackBall = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBallWidth, kBallWidth)];

self.blackBall.backgroundColor = GKColorRGB(12, 11, 17);

self.blackBall.layer.cornerRadius = kBallWidth * 0.5f;

self.blackBall.layer.masksToBounds = YES;

[self.greenBall addSubview:self.blackBall];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用UICollectionView来实现iOS仿抖音视频上下划动的效果。下面是一个简单的示例代码,演示了如何创建带有视频的UICollectionView,并实现上下滑动的效果。 首先,创建一个UICollectionView,并设置其滚动方向为垂直方向: ```swift let layout = UICollectionViewFlowLayout() layout.scrollDirection = .vertical let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height), collectionViewLayout: layout) collectionView.delegate = self collectionView.dataSource = self ``` 接下来,实现UICollectionViewDelegate和UICollectionViewDataSource协议的相关方法: ```swift extension ViewController: UICollectionViewDelegate, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return videos.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VideoCell", for: indexPath) as! VideoCell cell.videoURL = videos[indexPath.item] return cell } } class VideoCell: UICollectionViewCell { var videoURL: URL? { didSet { // 加载并显示视频 } } } ``` 在上述代码中,假设你已经有一个包含视频URL的数组videos,并且VideoCell是自定义的UICollectionViewCell子类,用于加载和显示视频。 最后,你可以在ViewController中添加滑动手势识别器,并在滑动手势回调方法中更新collectionView的contentOffset来实现上下滑动: ```swift let swipeGesture = UIPanGestureRecognizer(target: self, action: #selector(handleSwipe(_:))) collectionView.addGestureRecognizer(swipeGesture) @objc func handleSwipe(_ gesture: UIPanGestureRecognizer) { let translation = gesture.translation(in: collectionView) if gesture.state == .changed { collectionView.contentOffset.y = -translation.y } else if gesture.state == .ended { let velocity = gesture.velocity(in: collectionView) if velocity.y > 0 { // 向下滑动,加载下一页视频 } else { // 向上滑动,加载上一页视频 } } } ``` 在handleSwipe方法中,我们通过手势的translation来计算滑动的偏移量,并将其应用到collectionView的contentOffset上。在滑动手势结束时,你可以根据滑动的速度和方向来加载下一页或上一页的视频。 这只是一个简单的示例,你可以根据自己的需求进行进一步的定制和优化。希望对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值