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];

}

你可能感兴趣的:(iOS 签到动画之撒金币-粒子效果)