The fourth article, like the particle animation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.