美文网首页
类似今日头条点赞长按动画效果-CAEmitterLayer

类似今日头条点赞长按动画效果-CAEmitterLayer

作者: 爱闹的凡 | 来源:发表于2018-06-21 17:27 被阅读83次

    1. CAEmitterLayer是一款高性能的粒子引擎,用来创建实时的粒子动画:撒花、火焰、烟雾(因为没有合适的图,下面效果图将就着看吧😂)

    956B334A-F835-402F-A96F-CE1585FD54B4.png

    下面例子中详细说明用法,如有好的建议欢迎下面留言一起学习

        _containerView = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];
        _containerView.backgroundColor = [UIColor clearColor];
        [self.view addSubview:_containerView];
        
       /* CAEmitterLayer看上去像是许多CAEmitterCell的容器,这些CAEmitierCell定义了一个粒子效果。你将会为不同的粒子效果定义一个或多个CAEmitterCell作为模版,同时CAEmitterLayer负责基于这些模版实例化一个粒子流。一个CAEmitterCell类似于一个CALayer:它有一个contents属性可以定义为一个CGImage。*/
        
        CAEmitterLayer *emitter = [CAEmitterLayer layer];
        emitter.frame = self.containerView.bounds;
        [self.containerView.layer addSublayer:emitter];
        
        //configure emitter
        //控制着在视觉上粒子图片是如何混合的。你可能已经注意到了示例中我们把它设置为kCAEmitterLayerAdditive,它实现了这样一个效果:合并例子重叠部分的亮度使得看上去更亮。
        emitter.renderMode = kCAEmitterLayerAdditive;
        emitter.emitterPosition = CGPointMake(emitter.frame.size.width / 2.0, emitter.frame.size.height / 2.0);
        //是否将3D例子系统平面化到一个图层(默认值)或者可以在3D空间中混合其他的图层。
        emitter.preservesDepth = YES;
        //create a particle template
        CAEmitterCell *cell = [[CAEmitterCell alloc] init];
        cell.contents = (__bridge id)[UIImage imageNamed:@"warning.png"].CGImage;
        //每秒产生的粒子个数
        cell.birthRate = 150;
        //粒子的存在的时间
        cell.lifetime = 5.0;
        //color 指定一个可以混合图片内容颜色的混合色
        cell.color = [UIColor colorWithRed:1 green:0.5 blue:0.1 alpha:1.0].CGColor;
        //透明度变化的速度
        cell.alphaSpeed = -0.4;
        //速度
        cell.velocity = 50;
        cell.velocityRange = 50;
        //粒子范围,例如值为2π,粒子可以从360度喷射出来
        cell.emissionRange = M_PI*2 ;
        //经纬度确定喷射方向
        cell.emissionLatitude = 10;
        cell.emissionLongitude= 10;
        
        //粒子轨迹3D偏移
    //    cell.xAcceleration = 1;
        cell.zAcceleration = 10;
        cell.yAcceleration = 10;
        //add particle template to emitter
        emitter.emitterCells = @[cell];
    /```

    相关文章

      网友评论

          本文标题:类似今日头条点赞长按动画效果-CAEmitterLayer

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