like animated iOS comes with the particle engine's class caemitterlayer, which is a particle emitter system, each particle is an instance of Caemittercell. You can see what their respective properties are. There are two small points, one is caemitterlayer some properties have a multiplier effect on Caemittercell, such as birthrate, and the other is that there is no explicit way to stop the animation, including its parent class. Can think of the method, in addition to the layer erase, you can also set the Caemitterlayer birthrate to 0, so that the birth rate of each Caemittercell is 0, there will be no animation. classPraiseemitterview:uiview {Privatevar timer:nstimer?PrivateLet emitter:caemitterlayer! ={Let emitter=Caemitterlayer ()returnEmitter} () OverrideInit (frame:cgrect) {super.init (frame:frame) setup ()} required init?(coder Adecoder:nscoder) {super.init (Coder:adecoder) setup ()}Privatefunc Setup () {Emitter.frame=bounds Emitter.birthrate=0Emitter.emittershape=Kcaemitterlayerline emitter.emitterposition= Cgpointmake (0, Cgrectgetheight (bounds)) Emitter.emittersize=bounds.size emitter.emittercells= [Getemittercell (UIImage (named:"Comment")!. cgimage!), Getemittercell (UIImage (named:"flower_15")!. cgimage!)] Self.layer.addSublayer (emitter)} func Timeoutselector () {emitter.birthrate=0} func Emit () {emitter.birthrate=2Timer?. Invalidate () Timer= Nstimer.scheduledtimerwithtimeinterval (2, Target:self, selector: #selector (timeoutselector), Userinfo:nil, repeats:false) } PrivateFunc Getemittercell (Contentimage:cgimage)Caemittercell {Let Emittercell=Caemittercell () emittercell.contents=contentimage Emittercell.lifetime=2emittercell.birthrate=2emittercell.yacceleration= -70.0emittercell.xacceleration=0emittercell.velocity=20.0Emittercell.velocityrange=200.0Emittercell.emissionlongitude= CGFloat (0) Emittercell.emissionrange=cgfloat (m_pi_4) Emittercell.scale=0.8Emittercell.scalerange=0.8Emittercell.scalespeed= -0.15Emittercell.alpharange=0.75Emittercell.alphaspeed= -0.15 returnEmittercell}}
The fourth article, like the particle animation