美文网首页收藏ios
直播送礼物动画

直播送礼物动画

作者: 熊啊熊啊熊 | 来源:发表于2016-12-27 14:57 被阅读295次

之前公司一直在搞直播,需要弄送礼物动画,当时也不知道怎么做,本人也是小白一个,在网上找demo学习,现在把我学到的总结一下.
效果图:


Snip20161227_15.png

送鲜花参考http://www.jianshu.com/p/ca1e7cdafa48
送豪车是用关键帧动画,关键帧动画可以参考http://www.jianshu.com/p/a071bba99a1b
下面是代码:

- (void)animation {

    [UIView animateKeyframesWithDuration:4.0f delay:0.2 options:0 animations:^{
        
        __block CGPoint center = self.center;
        [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1.0/4 animations:^{
            self.transform = CGAffineTransformMakeScale(2, 2);
        }];
        
        [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1.5/4 animations:^{
            self.center = (CGPoint){center.x + [UIScreen mainScreen].bounds.size.width / 2 - 50, center.y + 200};
        }];
        
        [UIView addKeyframeWithRelativeStartTime:1.5/4 relativeDuration:2.5/4 animations:^{
            self.center = (CGPoint){center.x + center.x + [UIScreen mainScreen].bounds.size.width / 2 - 40, center.y + 210};
        }];
        
        [UIView addKeyframeWithRelativeStartTime:2.5/4 relativeDuration:3.5/4 animations:^{
            self.center = (CGPoint){center.x + [UIScreen mainScreen].bounds.size.width -50, center.y + 260};
        }];
        
        [UIView addKeyframeWithRelativeStartTime:3.5/4 relativeDuration:4.0/4 animations:^{
            self.center = (CGPoint){center.x + [UIScreen mainScreen].bounds.size.width + 50, center.y + 270};
        }];
        
    } completion:^(BOOL finished) {
        NSLog(@"删除动画");
        [self removeFromSuperview];
    }];
}

直播点赞,粒子动画,代码:

-(CAEmitterLayer *)emitterLayer {
    if (_emitterLayer == nil) {
        _emitterLayer = [CAEmitterLayer layer];
        //发射器在xy轴上的位置
        _emitterLayer.emitterPosition = CGPointMake(self.view.frame.size.width - 50, self.view.frame.size.height - 50);
        //发射器的尺寸大小
        _emitterLayer.emitterSize = CGSizeMake(20, 20);
        //渲染模式
        _emitterLayer.renderMode = kCAEmitterLayerUnordered;
        _emitterLayer.emitterShape = kCAEmitterLayerPoint;
        
        //创建保存粒子的数组
        NSMutableArray *array = [NSMutableArray array];
        //创建粒子
        for (int i = 0; i < 10; ++i) {
            //发射单元
            CAEmitterCell *stepCell = [CAEmitterCell emitterCell];
            //粒子创建速率 默认1/s
            stepCell.birthRate = 1;
            //粒子存活时间
            stepCell.lifetime = arc4random_uniform(4) + 1;
            //粒子的生存时间容差
            stepCell.lifetimeRange = 1.5;
            //粒子的内容
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"good%d_30x30",i]];
            stepCell.contents = (id)image.CGImage;
            //粒子的名字
            stepCell.name = [NSString stringWithFormat:@"%d",i];
            //粒子的运动速率
            stepCell.velocity = arc4random_uniform(100) + 100;
            //粒子速度的容差
            stepCell.velocityRange = 80;
            //粒子在xy平面的发射角度
            stepCell.emissionLongitude = M_PI + M_PI_2;
            //粒子发射角度容差
            stepCell.emissionRange = M_PI_2/6;
            //缩放比例
            stepCell.scale = 0.3;
            //添加到数组中
            [array addObject:stepCell];
        }
        //将粒子数组放入发射器中
        _emitterLayer.emitterCells = array;
        //将发射器添加到父类视图
        [self.view.layer addSublayer:_emitterLayer];
    }
    return _emitterLayer;
}

在下小白一个,以此在记录个人的成长,希望跟大家一起共同学习.

demo:https://github.com/xiongHenry/XT_SendGiftDemo

相关文章

  • 直播送礼物动画

    没事的时候写了一个送礼物的动画,本来用swift3.0写的,后来有人用的还是低版本的xcode,所以考虑兼容,用了...

  • 直播送礼物动画

    之前公司一直在搞直播,需要弄送礼物动画,当时也不知道怎么做,本人也是小白一个,在网上找demo学习,现在把我学到的...

  • 同步任务的插队实现笔记

    在实现直播送礼物功能的过程中,遇到一种场景 每个gif假设执行时间是1.5秒,那么直播间如果同时有40个人送礼物,...

  • 仿映客直播系统送礼物动画完善版本

    猫猫分享,必须精品 原创文章,欢迎转载。转载请注明:翟乃玉的博客地址:http://www.jianshu.com...

  • 【Android】直播App礼物弹窗及连送礼物动画

    一个Android直播App中,除了绚丽的礼物动画,首先要有礼物的弹出窗口,而且每个礼物都会有不同的类型,比如保时...

  • 直播间送礼物逻辑

    要想实现直播间的赠送礼物的功能,首先需要理解赠送礼物的机制; 实际上赠送礼物也是向聊天室里边的所有人发送一条消息,...

  • iOS 直播间送礼物逻辑

    iOS 直播间送礼物 先贴demo地址:GitHub demo基本实现了主流直播间礼物的逻辑 按照队列顺序显示用...

  • iOS 直播APP送礼物 关键帧动画内存优化

    由于要在项目中优化送礼物内存暴涨的问题,所以在网上找了很多资料。最后找到一个小伙伴的,非常不错,解决了我的问题。借...

  • 今日复盘

    ?感恩日记day139 1.感恩璐璐战友和我直播连麦,又聊了一个多小时。感恩在直播间送礼物、支持我直播的朋友们。 ...

  • 最基础的动画组合(包括直播送礼物的优化)

    http://www.tuicool.com/articles/EVNFjqN 直播APP常用动画效果 时间201...

网友评论

    本文标题:直播送礼物动画

    本文链接:https://www.haomeiwen.com/subject/gsfevttx.html