iOS 粒子效果

作者: e40c669177be | 来源:发表于2016-06-08 11:46 被阅读2028次

    参考文章 http://www.jianshu.com/p/df878cef6795

    static NSString *kX = @"curveX";
    static NSString *kY = @"curveY";
    
    //粒子效果
     -(void)effectOfParticle{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(self.bounds.size.width / 2 - 50, self.bounds.size.height / 2.0, 50, 50)];
         // view.backgroundColor = [UIColor yellowColor];
    view.layer.cornerRadius = 50;
    [self addSubview:view];
    
    //create particle emmitter layer
    //CAEmitterLayer负责发射粒子(粒子也可以发射粒子)
    CAEmitterLayer *emitter = [CAEmitterLayer layer];
    emitter.frame = view.bounds;
    //决定粒子发射形状的中心点
    emitter.emitterPosition = CGPointMake(100, 100);
    emitter.emitterZPosition = 3.0;
    emitter.emitterShape = kCAEmitterLayerCircle;//发射器形状
    emitter.emitterMode = kCAEmitterLayerVolume;//3d圆形的体积内发射
    
    emitter.preservesDepth = YES; //是否开启三维空间模式
    emitter.emitterDepth = 2.0;//发射器的深度,有时可能会产生立体效果
    emitter.spin = 50;//粒子的旋转角度
    [view.layer addSublayer:emitter];
    
    //configure emitter
    emitter.renderMode = kCAEmitterLayerAdditive;//渲染模式
    //emitter.emitterPosition = CGPointMake(emitter.frame.size.width /2.0, emitter.frame.size.height / 2.0);
    
    //creat a particle template]
    CAEmitterCell *cell = [[CAEmitterCell alloc] init];
    cell.contents = (__bridge id _Nullable)([UIImage imageNamed:@"2.png"].CGImage);
    cell.birthRate = 15.0;
    cell.lifetime = 5.0;
    cell.enabled = YES;//是否打开粒子的渲染效果
    //  cell.color = [UIColor colorWithRed:1 green:0.5 blue:0.1 alpha:1.0].CGColor;
    cell.alphaSpeed = -0.4;
    
    cell.velocity = 50; //粒子的速度
    cell.velocityRange = 70;//粒子的速度范围
    cell.emissionRange = M_PI * 2.0;
    //creat a particle template]
    CAEmitterCell *cell2 = [[CAEmitterCell alloc] init];
    cell2.contents = (__bridge id _Nullable)([UIImage imageNamed:@"2.png"].CGImage);
    cell2.birthRate = 15.0;
    cell2.lifetime = 5.0;
    cell2.color = [UIColor colorWithRed:1 green:0.5 blue:0.1 alpha:1.0].CGColor;
    cell2.alphaSpeed = -0.4;
    cell2.velocity = 50;
    cell2.velocityRange = 50;
    cell2.emissionRange = M_PI * 2.0;
    //add pareticle template to emitter
    emitter.emitterCells = @[cell,cell2];
    
    }
    

    相关文章

      网友评论

        本文标题:iOS 粒子效果

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