iOS - CAEmitterLayer 学习笔记一

其他参考博客:

http://my.oschina.net/u/2340880/blog/485095

http://www.cnblogs.com/YouXianMing/p/3785876.html

CAEmitterLayer这个类是QuartzCore框架中针对CoreAnimation提供的一个粒子放射系统。这些粒子是由CAEmitterCell这个类进行实例化的。

一、Specifying Particle Emitter Cells (说明粒子发射器的cell)

Declaration:

/* The array of emitter cells attached to the layer. Each object must
 * have the CAEmitterCell class. */

@property(nullable, copy) NSArray<CAEmitterCell *> *emitterCells;

Discussion:

Each object in the array must be an instance of the CAEmitterCell Class.

Avaliablility:

Avaliablility in iOS 5.0 and later.

 

二、Emitter Geometry (粒子几何)

(2.1)

RenderMode :Defines how particle cells are rendered into the CAMitterLayer.

Declaration:

/* A string defining how particles are composited into the layer's
 * image. Current options are `unordered' (the default), `oldestFirst',
 * `oldestLast', `backToFront' (i.e. sorted into Z order) and
 * `additive'. The first four use source-over compositing, the last
 * uses additive compositing. */

@property(copy) NSString *renderMode;

Discussion:

The possible values of render modes are shown in Emitter Modes. The default values is kCAEmitterLayerUnordered. // 无序的 e.g.

(2.2)

emitterPosistion:The position of the center of the particle emiiter. Animatable

Declaration:

/* The center of the emission shape. Defaults to (0, 0, 0). Animatable. */

@property CGPoint emitterPosition;

Discussion:

See Emitter Shape for details of how the emitterPosition related to the possible emitter shapes.

Default is (0.0, 0.0).

Availablility:

Available in iOS 5.0 and later.

(2.3)

emitterShape:Sepcifies the emitter shape.

Declaration:

/* A string defining the type of emission shape used. Current options are:
 * `point' (the default), `line', `rectangle', `circle', `cuboid' and
 * `sphere'. */

@property(copy) NSString *emitterShape;

Discussion:

The possible values for emitterMode are shown in Emitter Shape. The default value is kCAEmitterLayerPoint.

(2.4)

emitterZPosition:Specifies the center of the particle shape along the a-axis. Animatable.

Declaration:

@property CGFloat emitterZPosition;

Discussion:

See Emitter Shape for details of how the emitterZPosition relates to the possible emitter shapes.

(2.5)

emitterDepth:Determines the depath of the emitter shape.

Declaration:

@property CGFloat emitterDepth;

Discusstion:

How the emitter depth is applied depends on the emitter shape. See Emitter Shape for details. Depending on the value of emitterShape, this value may be ignored.

(2.6)

emitterSize:Determines the size of the particle emitter shape.

Declaration:

/* The size of the emission shape. Defaults to (0, 0, 0). Animatable.
 * Depending on the `emitterShape' property some of the values may be
 * ignored. */

@property CGSize emitterSize;

Discussion:

How the emitter size is applied depends on the emitter shape. See Emitter Shape for details. Depending on the value of emitteShaper, this value may be ignored.

 

三、Emitter Cell Attribute Multipliers

(3.1)scale:Defines a multiplier applied to the cell-defined particle scale.缩放比率

/* Multiplies the cell-defined particle scale. Defaults to one. Animatable. */

@property float scale;

(3.2)seed:Sepecifies the seed used to initialize the random number generator.

/* The seed used to initialize the random number generator. Defaults to
 * zero. Each layer has its own RNG state. For properties with a mean M
 * and a range R, random values of the properties are uniformly
 * distributed in the interval [M - R/2, M + R/2]. */

@property unsigned int seed;

(3.3)spin:Defines a multiplier applied to the cell-defined particle spin. 

/* Multiplies the cell-defined particle spin. Defaults to one. Animatable. */

@property float spin;

(2.4)velocity:Defines a multiplier applied to the cell-defined particle velocity.

/* Multiplies the cell-defined particle velocity. Defaults to one.
 * Animatable. */

@property float velocity;

(2.5)birthRate:Defines a multiplier that is applied to the cell-defined birth rate. Animatable

/* The birth rate of each cell is multiplied by this number to give the
 * actual number of particles created every second. Default value is one.
 * Animatable. */

@property float birthRate;

Discussion:

The birth rate of each cell is multiplied by this number to give the actual number of particles created every second. Default value is 1.0.

(2.6)emitterMode:Specities the emitter mode.

/* A string defining how particles are created relative to the emission
 * shape. Current options are `points', `outline', `surface' and
 * `volume' (the default). */

@property(copy) NSString *emitterMode;

Discussion:

The possible values for emitterMode are shown in Emitter Modes. The default value is kCAEmitterLayerVolume.

(2.7)lifetime:Defines a multiplier applied to the cell-defined lifetime range when particles are created.

/* The cell lifetime range is multiplied by this value when particles are
 * created. Defaults to one. Animatable. */

@property float lifetime;

(2.8)preservesDepth:Defines whether the layer flattens the particles into its plane.

/* When true the particles are rendered as if they directly inhabit the
 * three dimensional coordinate space of the layer's superlayer, rather
 * than being flattened into the layer's plane first. Defaults to NO.
 * If true, the effect of the `filters', `backgroundFilters' and shadow-
 * related properties of the layer is undefined. */

@property BOOL preservesDepth;

Discussion:

If YES, the layer renders its particles as if they directly inhabit the three-dimensional coordinate space of the layer’s superlayer. When enabled, the effect of the layer’s filters, backgroundFilters, and shadow related properties is undefined.

Default is NO.

 

CAEmitterLayer的类:

/* CoreAnimation - CAEmitterLayer.h

   Copyright (c) 2007-2015, Apple Inc.
   All rights reserved. */

/* Particle emitter layer.
 *
 * Each emitter has an array of cells, the cells define how particles
 * are emitted and rendered by the layer.
 *
 * Particle system is affected by layer's timing. The simulation starts
 * at layer's beginTime.
 *
 * The particles are drawn above the backgroundColor and border of the
 * layer. */

#import <QuartzCore/CALayer.h>

@class CAEmitterCell;

NS_ASSUME_NONNULL_BEGIN

@interface CAEmitterLayer : CALayer

/* The array of emitter cells attached to the layer. Each object must
 * have the CAEmitterCell class. */

@property(nullable, copy) NSArray<CAEmitterCell *> *emitterCells;

/* The birth rate of each cell is multiplied by this number to give the
 * actual number of particles created every second. Default value is one.
 * Animatable. */

@property float birthRate;

/* The cell lifetime range is multiplied by this value when particles are
 * created. Defaults to one. Animatable. */

@property float lifetime;

/* The center of the emission shape. Defaults to (0, 0, 0). Animatable. */

@property CGPoint emitterPosition;
@property CGFloat emitterZPosition;

/* The size of the emission shape. Defaults to (0, 0, 0). Animatable.
 * Depending on the `emitterShape' property some of the values may be
 * ignored. */

@property CGSize emitterSize;
@property CGFloat emitterDepth;

/* A string defining the type of emission shape used. Current options are:
 * `point' (the default), `line', `rectangle', `circle', `cuboid' and
 * `sphere'. */

@property(copy) NSString *emitterShape;

/* A string defining how particles are created relative to the emission
 * shape. Current options are `points', `outline', `surface' and
 * `volume' (the default). */

@property(copy) NSString *emitterMode;

/* A string defining how particles are composited into the layer's
 * image. Current options are `unordered' (the default), `oldestFirst',
 * `oldestLast', `backToFront' (i.e. sorted into Z order) and
 * `additive'. The first four use source-over compositing, the last
 * uses additive compositing. */

@property(copy) NSString *renderMode;

/* When true the particles are rendered as if they directly inhabit the
 * three dimensional coordinate space of the layer's superlayer, rather
 * than being flattened into the layer's plane first. Defaults to NO.
 * If true, the effect of the `filters', `backgroundFilters' and shadow-
 * related properties of the layer is undefined. */

@property BOOL preservesDepth;

/* Multiplies the cell-defined particle velocity. Defaults to one.
 * Animatable. */

@property float velocity;

/* Multiplies the cell-defined particle scale. Defaults to one. Animatable. */

@property float scale;

/* Multiplies the cell-defined particle spin. Defaults to one. Animatable. */

@property float spin;

/* The seed used to initialize the random number generator. Defaults to
 * zero. Each layer has its own RNG state. For properties with a mean M
 * and a range R, random values of the properties are uniformly
 * distributed in the interval [M - R/2, M + R/2]. */

@property unsigned int seed;

@end

/** `emitterShape' values. **/

CA_EXTERN NSString * const kCAEmitterLayerPoint
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerLine
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerRectangle
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerCuboid
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerCircle
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerSphere
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);

/** `emitterMode' values. **/

CA_EXTERN NSString * const kCAEmitterLayerPoints
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerOutline
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerSurface
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerVolume
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);

/** `renderMode' values. **/

CA_EXTERN NSString * const kCAEmitterLayerUnordered
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerOldestFirst
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerOldestLast
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerBackToFront
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);
CA_EXTERN NSString * const kCAEmitterLayerAdditive
    __OSX_AVAILABLE_STARTING (__MAC_10_6, __IPHONE_5_0);

NS_ASSUME_NONNULL_END
CAEmitterLayer

 

posted @ 2016-01-19 14:19  lvable  阅读(473)  评论(0编辑  收藏  举报