iOS 签到动画之撒金币-粒子效果

效果图

话不多说,项目改版,旧的功能需要移除,拆分出来记录一下以便需要时回顾。

https://github.com/tyjlp/throwingCoin_CAEmitterLayer.git


-(void)startAnimationWithLayer:(CALayer*)superLayer{

   //初始化粒子发射器

    [self initEmitterLayerWithSuperLayer:superLayer];

    CABasicAnimation * effectAnimation = [CABasicAnimation animationWithKeyPath:@"emitterCells.zanShape.birthRate"];

    effectAnimation.fromValue= [NSNumbernumberWithFloat:30];

    effectAnimation.toValue= [NSNumbernumberWithFloat:0];

    effectAnimation.duration=2.0f;

    effectAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    effectAnimation.delegate=self;

    [self.emitterLayeraddAnimation:effectAnimationforKey:@"zanCount"];

    //

    [self playSoundWithSoundName:@"签到金币音效.mp3"];

}

-(void)initEmitterLayerWithSuperLayer:(CALayer*)superLayer{

    //发射源

    CAEmitterLayer * emitter = [CAEmitterLayer layer];

    emitter.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);

    [superLayeraddSublayer:self.emitterLayer= emitter];

    //发射源形状

    emitter.emitterShape = kCAEmitterLayerCircle;

    //发射模式

    emitter.emitterMode = kCAEmitterLayerOutline;

    //渲染模式

    //    emitter.renderMode = kCAEmitterLayerAdditive;

    //发射位置

    emitter.emitterPosition = CGPointMake(emitter.frame.size.width/2, emitter.frame.size.height/2);

    //发射源尺寸大小

    emitter.emitterSize=CGSizeMake(20,20);

    // 从发射源射出的粒子

    CAEmitterCell * cell = [CAEmitterCell emitterCell];

    cell.name=@"zanShape";

    //粒子要展现的图片

    cell.contents= (__bridgeid)[UIImageimageNamed:@"coin"].CGImage;

    //    cell.contents = (__bridge id)[UIImage imageNamed:@"EffectImage"].CGImage;

    //            cell.contentsRect = CGRectMake(100, 100, 100, 100);

    //粒子透明度在生命周期内的改变速度

    cell.alphaSpeed= -0.5;

    //生命周期

    cell.lifetime=3.0;

    //粒子产生系数(粒子的速度乘数因子)

    cell.birthRate=0;

    //粒子速度

    cell.velocity=300;

    //速度范围

    cell.velocityRange = 100;

    //周围发射角度

    cell.emissionRange=M_PI/8;

    //发射的z轴方向的角度

    cell.emissionLatitude = -M_PI;

    //x-y平面的发射方向

    cell.emissionLongitude = -M_PI / 2;

    //粒子y方向的加速度分量

    cell.yAcceleration = 250;

    emitter.emitterCells=@[cell];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift版本点击这里欢迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh阅读 25,586评论 7 249
  • 我对生活的全部认识局限于学校,我以为在学校可以习得解决大多数问题的办法,把学习所得应用在工作中,又有办法。直到毕业...
    潇筱阅读 309评论 0 2
  • 早课抄了葡萄牙诗人卡蒙斯的诗歌《当我离开的时候》。晨风中,轻声細读卡蒙斯的这首小诗,总会想到达利的《费盖莱斯的狂欢...
    东丰林波阅读 335评论 0 0
  • 这不是笑话,看完以后你的灵魂会严肃点! 这不是脏话,请允许我用牛逼一词,因为我真的找不到比这个词再合适的了! 这不...
    浩瀚海洋阅读 495评论 0 1
  • 初衷:一直想要出国游的我终于有机会可以去看看外面的世界。 为啥会选择泰国呢? 第一,风景不错; 第二,语言沟通没什...
    拾柒1717阅读 2,002评论 4 6