UI Basics-Particle animation

Source: Internet
Author: User

Particle transmitter: caemitterlayer particle: Caemittercell gradient layer: Cagradientlayer

Add code:

@interfaceRootviewcontroller () @property (nonatomic, strong) Caemitterlayer*Emitterlayer;@end@implementationRootviewcontroller-(Caemitterlayer *) emitterlayer{if(_emitterlayer) {return_emitterlayer; } _emitterlayer=[[Caemitterlayer alloc]init];    [Self.view.layer Addsublayer:_emitterlayer]; return_emitterlayer;}- (void) viewdidload {[Super viewdidload]; //Do any additional setup after loading the view.Self.view.backgroundColor =[Uicolor Whitecolor]; Self.title=@"Big head son"; Uiimageview*view =[[Uiimageview alloc]initwithframe:self.view.frame]; //view.center = Cgpointmake (200,450);View.contentmode =Uiviewcontentmodescaleaspectfit; View.image= [UIImage imagenamed:@"1.jpg"];        [Self.view Addsubview:view]; Self.emitterLayer.frame= CGRectMake (0,0, Self.view.frame.size.width, -);//Self.view.backgroundColor = [Uicolor blackcolor]; //set the number of particle senders sent per secondSelf.emitterLayer.birthRate =1; //Self.emitterLayer.emitterPosition Center PointSelf.emitterLayer.position = Cgpointmake ( -, the); Self.emitterLayer.emitterShape=kcaemitterlayercircle; //set the style of the particle senderSelf.emitterLayer.renderMode =Kcaemitterlayeroldestlast; Self.emitterLayer.emitterMode=Kcaemitterlayervolume; Nsmutablearray*array =[[Nsmutablearray alloc]init];  for(intI=0; i<5; i++) {Caemittercell*cell3 =[Caemittercell Emittercell]; Cell3.contents= (ID) [UIImage imagenamed:[nsstring stringWithFormat:@"Peach Heart%d", i+1]].        Cgimage; //Particle Birth RateCell3.birthrate =1; //survival time, unit secondsCell3.lifetime =5; Cell3.lifetimerange=2; //Send SpeedCell3.velocity = -; Cell3.velocityrange= -; //direction of particle sendingCell3.emissionlatitude = -* (i+1) *m_pi/ the; //the acceleration sentCell3.yacceleration =- -; //range of emitted particles-radiansCell3.emissionrange = $; //Put the cell on the particle transmitter .[Array addobject:cell3]; } self.emitterLayer.emitterCells=Array; //Create a Gradient layer objectCagradientlayer *layer =[Cagradientlayer layer]; Layer.frame=Self.view.frame; //transparency of LayersLayer.opacity =0.2; //set the start point of a layer color gradientLayer.startpoint = Cgpointmake (0,0); //set the end point of a layer color gradientLayer.endpoint = Cgpointmake (1,0.5); //percent Array of color gradientsLayer.locations = @[@0.2,@0.6]; //An array of gradient colors does not accept a Cgcolor type that is strongly converted to an ID typeLayer.colors = @[(ID) [Uicolor Redcolor]. Cgcolor, (ID) [Uicolor Whitecolor]. Cgcolor, (ID) [Uicolor Cyancolor].    Cgcolor,]; [Self.view.layer Addsublayer:layer];//}

:

UI Basics-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.