- (void)createAnimaton {
    // 实例化发射器
    CAEmitterLayer *snowLayer = [CAEmitterLayer layer];
    // 设置大小
    snowLayer.frame = self.view.bounds;
    // 指定发射源位置
    snowLayer.emitterPosition = CGPointMake(self.view.bounds.size.width / 2, -10);
    // 指定发射源的大小
    snowLayer.emitterSize = CGSizeMake(self.view.bounds.size.width, 0);
    // 指定发射源的形状
    snowLayer.emitterShape = kCAEmitterLayerLine;
    // 指定发射源的模式
    snowLayer.emitterMode = kCAEmitterLayerOutline;
    // 添加
    [self.view.layer addSublayer:snowLayer];
    
    CAEmitterCell *cell = [CAEmitterCell emitterCell];
    // 每秒产生的????数
    cell.birthRate = 5;
    // 存活时间
    cell.lifetime = 20;
    // 初速度
    cell.velocity = 5;
    // 加速度
    cell.yAcceleration = 10;
    // 设置发散角度
    cell.emissionRange = 10;
    // 设置图片
    cell.contents = (__bridge id _Nullable)([UIImage imageNamed:@"2"].CGImage);
    // 设置图片的缩放比例
    cell.scale = 0.5;
    // 开始动画
    snowLayer.emitterCells = [NSArray arrayWithObject:cell];
}

 效果展示:

iOS--雪花掉落特效

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-01
  • 2021-09-05
  • 2021-08-22
  • 2022-12-23
  • 2022-02-24
猜你喜欢
  • 2022-12-23
  • 2023-01-01
  • 2021-08-28
  • 2022-12-23
  • 2021-07-23
  • 2021-08-18
  • 2022-01-12
相关资源
相似解决方案