iOS核心动画-粒子效果(CAEmitterLayer)

2019-06-21  本文已影响0人  Tobesky

概述

自iOS5,苹果引入了新的CALayer子类CAEmitterLayer

CAEMitterCell

CAEMitterCell的属性基本上可以分为三种:

// 配置CAEmitterCell
CAEmitterCell * colorBallCell = [CAEmitterCell emitterCell];
//粒子名称
colorBallCell.name = @"colorBallCell";
//粒子产生率,默认为0
colorBallCell.birthRate = 20.f;
//粒子生命周期
colorBallCell.lifetime = 10.f;
//粒子速度,默认为0
colorBallCell.velocity = 40.f;
//粒子速度平均量
colorBallCell.velocityRange = 100.f;
//x,y,z方向上的加速度分量,三者默认都是0
colorBallCell.yAcceleration = 15.f;
//指定纬度,纬度角代表了在x-z轴平面坐标系中与x轴之间的夹角,默认0:
colorBallCell.emissionLongitude = M_PI; // 向左
//发射角度范围,默认0,以锥形分布开的发射角度。角度用弧度制。粒子均匀分布在这个锥形范围内;
colorBallCell.emissionRange = M_PI_4; // 围绕X轴向左90度
// 缩放比例, 默认是1
colorBallCell.scale = 0.2;
// 缩放比例范围,默认是0
colorBallCell.scaleRange = 0.1;
// 在生命周期内的缩放速度,默认是0
colorBallCell.scaleSpeed = 0.02;
// 粒子的内容,为CGImageRef的对象
colorBallCell.contents = (id)[[UIImage imageNamed:@"circle_white"] CGImage];
//颜色
colorBallCell.color = [[UIColor colorWithRed:0.5 green:0.f blue:0.5 alpha:1.f] CGColor];
// 粒子颜色red,green,blue,alpha能改变的范围,默认0
colorBallCell.redRange = 1.f;
colorBallCell.greenRange = 1.f;
colorBallCell.alphaRange = 0.8;
// 粒子颜色red,green,blue,alpha在生命周期内的改变速度,默认都是0
colorBallCell.blueSpeed = 1.f;
colorBallCell.alphaSpeed = -0.1f;

CAEmitterLayer

CAEmitterLayer的属性它自己控制着整个粒子系统的位置和形状。

一些属性比如birthRate,lifetime和celocity,这些属性在CAEmitterCell中也有。

CAEMitterCell的属性很多,组合属性获得更多的粒子效果。

// 设置CAEmitterLayer
CAEmitterLayer * colorBallLayer = [CAEmitterLayer layer];
[self.view.layer addSublayer:colorBallLayer];
self.colorBallLayer = colorBallLayer;
    
//发射源的尺寸大小
colorBallLayer.emitterSize = self.view.frame.size;
//发射源的形状
colorBallLayer.emitterShape = kCAEmitterLayerPoint;
//发射模式
colorBallLayer.emitterMode = kCAEmitterLayerPoints;
//粒子发射形状的中心点
colorBallLayer.emitterPosition = CGPointMake(self.view.layer.bounds.size.width, 0.f);

CAEmitterLayer添加CAEmitterCell

colorBallLayer.emitterCells = @[colorBallCell];
上一篇 下一篇

猜你喜欢

热点阅读