美文网首页
下雪动画 CAEmitterLayer CAEmitterCel

下雪动画 CAEmitterLayer CAEmitterCel

作者: 梓华 | 来源:发表于2019-11-27 17:44 被阅读0次

    参考:https://ios.devdon.com/archives/1046

        _snowEmitter = [CAEmitterLayer layer];
        
        CGRect rect = CGRectMake(0.0, 0.0, windowSize.width, 40.0);
        
        _snowEmitter.emitterPosition    = CGPointMake(rect.size.width / 2, -rect.size.height / 2);
        _snowEmitter.emitterSize        = rect.size;
        
        _snowEmitter.emitterMode        = kCAEmitterLayerOutline;
        _snowEmitter.emitterShape       = kCAEmitterLayerLine;
        _snowEmitter.renderMode         = kCAEmitterLayerOldestLast;
        
        CAEmitterCell *confetti = [CAEmitterCell emitterCell];
        
        confetti.contents = (__bridge id)[[UIImage imageNamed:@"snow.png"] CGImage];
        confetti.name = @"confetti";
        confetti.birthRate = 5;
        confetti.lifetime = 20.0;
        
        confetti.velocity = 30;
        confetti.velocityRange = 100;
        
        confetti.emissionLongitude = (CGFloat) M_PI;
        
        confetti.yAcceleration = 25;
        
        confetti.alphaRange = 1.0;
        confetti.alphaSpeed = -0.1;
        
        confetti.spinRange = 10.0;
        confetti.scale = 0.6;
        confetti.scaleRange = 0.6;
        
        _snowEmitter.emitterCells = [NSArray arrayWithObject:confetti];
        
        [superLayer insertSublayer:_snowEmitter atIndex:0];
    

    相关文章

      网友评论

          本文标题:下雪动画 CAEmitterLayer CAEmitterCel

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