当前位置: 首页 > 工具软件 > emitter-kit > 使用案例 >

emitter(粒子动画)

傅元龙
2023-12-01
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CAEmitterLayer *emitterLayer = [CAEmitterLayer layer];
    
    //设置Layer位置大小
    emitterLayer.frame = CGRectMake(100, 100, 200, 200);
    
    CGRect bounds = emitterLayer.bounds;
    
    //背景色
    emitterLayer.backgroundColor = [UIColor grayColor].CGColor;
    //发射位置设置为Layer的中心
    emitterLayer.emitterPosition = CGPointMake(bounds.size.width/2, bounds.size.height/2);
    //发射区域的大小
    emitterLayer.emitterSize = CGSizeMake(200, 200);
    //从Layer的边框产生粒子
    emitterLayer.emitterMode    = kCAEmitterLayerOutline;
    //发射器的形状为矩形
    emitterLayer.emitterShape    = kCAEmitterLayerLine;
    emitterLayer.renderMode = kCAEmitterLayerAdditive;
    [self.view.layer addSublayer:emitterLayer];
    
    CAEmitterCell *cell1 = [CAEmitterCell emitterCell];
    cell1.lifetime = 2;
    cell1.lifetimeRange = 10;
    cell1.birthRate = 1;
    cell1.velocity = 10;
    cell1.spin = M_PI_4;
    cell1.spinRange = M_PI;
    cell1.contents = (__bridge id)[UIImage imageNamed:@"DazStarOutline"].CGImage;
    cell1.color = [UIColor redColor].CGColor;
    emitterLayer.emitterCells = @[cell1];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
 类似资料: