高仿映客之七視頻播放的點(diǎn)贊動(dòng)畫和彈幕文字

前言####

本文是高仿映客項(xiàng)目的續(xù)集篇,如果想了解高仿映客項(xiàng)目的更多詳細(xì)資料可以點(diǎn)擊以下鏈接:
映客源碼下載地址:高仿映客項(xiàng)目源碼
映客系列詳細(xì)解說(shuō)目錄:映客系列詳細(xì)解說(shuō)目錄

點(diǎn)贊和彈幕動(dòng)畫.gif
點(diǎn)贊和彈幕動(dòng)畫.gif

點(diǎn)贊動(dòng)畫####

點(diǎn)贊動(dòng)畫仔細(xì)觀察不難發(fā)現(xiàn),其實(shí)是一個(gè)組動(dòng)畫,凡是什么復(fù)雜的動(dòng)畫都可以一步一步拆解為簡(jiǎn)單的動(dòng)畫一一實(shí)現(xiàn)
組動(dòng)畫的構(gòu)成:路徑動(dòng)畫和關(guān)鍵幀動(dòng)畫組成

首先點(diǎn)擊點(diǎn)贊按鈕的時(shí)候創(chuàng)建一個(gè)imageView

UIImage *praise = [UIImage imageNamed:@"me_other_followed"];
UIImageView *praiseView = [[UIImageView alloc]initWithImage:praise];
praiseView.frame = CGRectMake(LZBSCREEN__WIDTH * 0.5 - praise.size.width *0.5, LZBSCREEN__HEIGHT, praise.size.width, praise.size.width);
[self.view insertSubview:praiseView belowSubview:self.view];

繪制這個(gè)imageView移動(dòng)的路徑

//動(dòng)畫初始值
CGFloat animationH = LZBSCREEN__HEIGHT * 0.5;
//繪制動(dòng)畫路徑
CGFloat offset = 150;
UIBezierPath *animationPath = [UIBezierPath bezierPath];
CGPoint startPoint = praiseView.center;
CGPoint endPoint = CGPointMake(praiseView.center.x, LZBSCREEN__HEIGHT * 0.5);
CGPoint controlPoint1 = CGPointMake(praiseView.center.x -arc4random_uniform(offset) ,LZBSCREEN__HEIGHT - animationH/4);
CGPoint controlPoint2 = CGPointMake(praiseView.center.x +arc4random_uniform(offset), LZBSCREEN__HEIGHT - animationH*3/4);
[animationPath moveToPoint:startPoint];
[animationPath addCurveToPoint:endPoint controlPoint1:controlPoint1 controlPoint2:controlPoint2];
 //關(guān)鍵幀動(dòng)畫,實(shí)現(xiàn)整體圖片位移
CGFloat duration = 3.0;
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyFrameAnimation.path = animationPath.CGPath;
keyFrameAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
keyFrameAnimation.duration = duration ;//往上飄動(dòng)畫時(shí)長(zhǎng),可控制速度

實(shí)現(xiàn)imageView放大縮小的關(guān)鍵幀動(dòng)畫

  //關(guān)鍵幀動(dòng)畫,實(shí)現(xiàn)整體圖片放大縮小
CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
scale.values = @[@1.0,@1.4,@1.8,@2.0,@1.8,@1.6,@1.4,@1.0];
scale.duration = duration;
scale.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];

實(shí)現(xiàn)組動(dòng)畫疊加

 //增加組動(dòng)畫
CAAnimationGroup *grounp = [CAAnimationGroup animation];
grounp.animations = @[scale,keyFrameAnimation];
grounp.duration = duration;
[praiseView.layer addAnimation:grounp forKey:@"positionAniamtion"];

最后imageView移出動(dòng)畫區(qū)域 移除imageView
//消失動(dòng)畫

[UIView animateWithDuration:duration animations:^{
    praiseView.alpha = 0.0;
} completion:^(BOOL finished) {
    [praiseView removeFromSuperview];
}];

文字評(píng)論彈幕動(dòng)畫###

彈幕動(dòng)畫使用的是自定義LZBFlyLabel來(lái)做的

//text彈幕文字    open打開(kāi)隨機(jī)顏色  velocity移動(dòng)速度
 - (instancetype)initWithFlyText:(NSString *)text openRandColor:(BOOL)open moveVelocity:(CGFloat)velocity;

具體實(shí)現(xiàn)

  - (instancetype)initWithFlyText:(NSString *)text openRandColor:(BOOL)open moveVelocity:(CGFloat)velocity
{
self.offsetY = arc4random()%(200);  //200表示隨機(jī)的最大偏移量
self.font = LZBFlyLabel_Font;  //設(shè)置字體
self.text = text;
 if(self = [super initWithFrame:CGRectMake(getScreenWidth(), self.offsetY, getScreenWidth(), ceil([self getTextSize].height))])
  {
   self.textColor = open?[self getRandColor]:[UIColor redColor];   //設(shè)置顏色
   self.textAlignment = NSTextAlignmentCenter;
   self.numberOfLines = 0;
   [self addFlyAnimationWithVelocity:velocity];  //增加滾動(dòng)動(dòng)畫
  }
return self;
}

增加動(dòng)畫效果

   - (void)addFlyAnimationWithVelocity:(CGFloat)velocity
{
LZBWeakSelf(weakSelf);
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView animateWithDuration:20.0 animations:^{
    weakSelf.frame = CGRectMake(-weakSelf.frame.size.width, weakSelf.offsetY, weakSelf.frame.size.width, ceil([self getTextSize].height));
} completion:^(BOOL finished) {
   [weakSelf removeFromSuperview];
}];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 動(dòng)畫的繼承結(jié)構(gòu) CAAnimation{CAPropertyAnimation{CABasicAnimation{...
    早起的蟲兒子被鳥吃閱讀 907評(píng)論 0 1
  • 在iOS中隨處都可以看到絢麗的動(dòng)畫效果,實(shí)現(xiàn)這些動(dòng)畫的過(guò)程并不復(fù)雜,今天將帶大家一窺iOS動(dòng)畫全貌。在這里你可以看...
    F麥子閱讀 5,143評(píng)論 5 13
  • 在iOS中隨處都可以看到絢麗的動(dòng)畫效果,實(shí)現(xiàn)這些動(dòng)畫的過(guò)程并不復(fù)雜,今天將帶大家一窺ios動(dòng)畫全貌。在這里你可以看...
    每天刷兩次牙閱讀 8,572評(píng)論 6 30
  • Core Animation Core Animation,中文翻譯為核心動(dòng)畫,它是一組非常強(qiáng)大的動(dòng)畫處理API,...
    45b645c5912e閱讀 3,069評(píng)論 0 21
  • iOS動(dòng)畫篇之CoreAnimation動(dòng)畫 9月 22, 2016發(fā)布在Objective-C App如果想被大...
    白水灬煮一切閱讀 2,135評(píng)論 0 0