固予

iOS雪花动画

2016-03-15  本文已影响312人  Realank
雪花效果
    //create particle emitter layer
    CAEmitterLayer *emitter = [CAEmitterLayer layer];
    emitter.frame = CGRectMake(0, -50, self.view.bounds.size.width, 50);
    [self.view.layer addSublayer:emitter];
    
    emitter.emitterShape = kCAEmitterLayerRectangle;
    //configure emitter
//    emitter.renderMode = kCAEmitterLayerAdditive;
    emitter.emitterPosition = CGPointMake(emitter.frame.size.width / 2.0, emitter.frame.size.height / 2.0);
    emitter.emitterSize = emitter.frame.size;
    
    //create a particle template
    CAEmitterCell *cell = [[CAEmitterCell alloc] init];
    cell.contents = (__bridge id)[UIImage imageNamed:@"snow"].CGImage;
    cell.contentsScale = 7;
    
    cell.birthRate = 100;
    cell.lifetime = 5.0;
    cell.lifetimeRange = 5;
    
    cell.redRange = 0.1;
    cell.greenRange = 0.1;
    cell.blueRange = 0.1;
    
    cell.alphaRange = 0.8;
    cell.alphaSpeed = -0.10;
    
    cell.yAcceleration = 30;
    cell.xAcceleration = 20;
    cell.velocity = 20;
    cell.velocityRange = 200;
    cell.emissionRange = M_PI_2;
    cell.emissionLongitude = - M_PI;
    
    //add particle template to emitter
    emitter.emitterCells = @[cell];
上一篇下一篇

猜你喜欢

热点阅读