IOS Circle's Zoom animation effect

Source: Internet
Author: User

First step: Create a view to add this view to the current controller

Such as:

CGFloat Timew =* Timean = [[timeanimation alloc]initwithframe:cgrectmake (0,0, Timew, Timew)];     = Cgpointmake (self.view.bounds.size.width*0.5, self.view.bounds.size.height *0.5); [ Self.view Addsubview:timean];

Step Two: Add the following code to the view's. m file

#define PI 3.14159265358979323846

#define Kradius self.bounds.size.width*0.1

-(Instancetype) initWithFrame: (cgrect) frame{if(self =[Super Initwithframe:frame]) {Self.frame=frame; Self.backgroundcolor=[Uicolor Clearcolor]; }    returnSelf ;}- (void) DrawRect: (cgrect) Rect {cgcontextref context=Uigraphicsgetcurrentcontext ();    [Self greenround:context]; Self.alpha=0.5; [Self test];}-(void) test{//2. Create a scaled animation objectCabasicanimation *scale =[cabasicanimation animation]; Scale.keypath=@"Transform.scale"; Scale.fromvalue=[nsnumber numberwithfloat:0.0]; Scale.tovalue=[nsnumber numberwithfloat:1.0]; Cabasicanimation*scale1 =[cabasicanimation animation]; Scale1.keypath=@"Opacity"; Scale1.fromvalue=[nsnumber numberwithfloat:1.0]; Scale1.tovalue=[nsnumber numberwithfloat:0.0]; //4. Add all animations to the animation groupCaanimationgroup *group =[Caanimationgroup animation]; Group.animations=@[scale,scale1]; Group.duration=.6; Group.repeatcount=huge_valf; Group.removedoncompletion=NO; Group.fillmode=kcafillmodeforwards; [Self.layer Addanimation:group forkey:nil];}/** Draw a green circle*/-(void) Greenround: (cgcontextref) context{cgcontextsetrgbstrokecolor (context, -/255.0,177/255.0, the/255.0,1);//Color of brush linesCgcontextsetlinewidth (Context,4.0);//the width of the line//x, y is the dot coordinate, radius radius, startangle is the starting Radian, Endangle is the ending Radian, clockwise 0 is clockwise, and 1 is counterclockwise. Cgcontextaddarc (Context, Self.bounds.size.width *0.5, self.bounds.size.height*0.5, self.bounds.size.width*0.21,0,2*PI,0);//Add a circleCgcontextdrawpath (context, kcgpathstroke);//Draw Path}

IOS Circle's Zoom animation effect

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.