Animation along the besell Curve

Source: Internet
Author: User

Animation along the besell Curve

As follows:

Source code:

//// Rootviewcontroller. M /// copyright (c) 2014 y. x. all rights reserved. // # import "rootviewcontroller. H "# import" yxgcd. H "@ interface rootviewcontroller () @ property (nonatomic, strong) gcdtimer * timer; @ end @ implementation rootviewcontroller-(void) viewdidload {[Super viewdidload]; cashapelayer * shapelayer = [cashapelayer layer]; shapelayer. path = [self bezierpath]. cgpath; shapelayer. fillcolor = [uicolor clearcolor]. cgcolor; shapelayer. strokecolor = [uicolor redcolor]. cgcolor; [self. view. layer addsublayer: shapelayer]; cgfloat max = 0.7f; cgfloat Gap = 0.1f; _ timer = [[gcdtimer alloc] initinqueue: [gcdqueue mainqueue]; [_ timer event: ^ {cabasicanimation * anistart = [cabasicanimation animationwithkeypath: @ "strokestart"]; anistart. fromvalue = [nsnumber numberwithfloat: 0.f]; anistart. tovalue = [nsnumber numberwithfloat: Max]; anistart. duration = 10.f; cabasicanimation * aniend = [cabasicanimation animationwithkeypath: @ "strokeend"]; aniend. fromvalue = [nsnumber numberwithfloat: 0.f + Gap]; aniend. tovalue = [nsnumber numberwithfloat: MAX + Gap]; aniend. duration = 10.f; caanimationgroup * Group = [caanimationgroup animation]; group. duration = 10.f; group. animations = @ [aniend, anistart]; shapelayer. strokestart = max; shapelayer. strokeend = MAX + gap; [shapelayer addanimation: group forkey: Nil];} timeinterval: nsec_per_sec * 11]; [_ timer start];}-(uibezierpath *) bezierpath {Pipeline * bezierpath = [describezierpath]; [bezierpath movetopoint: cgpointmake (0,153)]; [bezierpath addcurvetopoint: cgpointmake (7.15, 68.33) controlpoint1: cgpointmake (0,153) controlpoint2: cgpointmake (3.87, 81.7)]; [bezierpath addcurvetopoint: cgpointmake (25.04, 19.69) controlpoint1: cgpointmake (12.37, 47.12) controlpoint2: cgpointmake (18.32, 30.36)]; [bezierpath addcurvetopoint: cgpointmake (52.34, 11.11) controlpoint1: cgpointmake (33.25, 6.65) controlpoint2: cgpointmake (42.42, 3.15)]; [bezierpath addcurvetopoint: cgpointmake (66.37, 35.65) controlpoint1: cgpointmake (59.1, 16.55) controlpoint2: cgpointmake (63.57, 24.69)]; [bezierpath addcurvetopoint: cgpointmake (70.44, 68.48) controlpoint1: cgpointmake (68.59, 44.35) controlpoint2: cgpointmake (69.67, 53.94)]; [bezierpath addcurvetopoint: cgpointmake (70.82, 76.33) controlpoint1: cgpointmake (70.55, 70.64) controlpoint2: cgpointmake (70.62, 72.11)]; [bezierpath addcurvetopoint: cgpointmake (78.01, 120.77) controlpoint1: cgpointmake (72.01, 101.67) controlpoint2: cgpointmake (73.36, 111.89)]; [bezierpath addcurvetopoint: cgpointmake (113.44, 130.02) controlpoint1: cgpointmake (84.01, 132.24) controlpoint2: cgpointmake (94.99, 135.64)]; [bezierpath addcurvetopoint: cgpointmake (160.6, 80.19) controlpoint1: cgpointmake (136.37, 123.04) controlpoint2: cgpointmake (150.08, 106.8)]; [bezierpath addcurvetopoint: cgpointmake (165.62, 66.27) controlpoint1: cgpointmake (162.24, 76.04) controlpoint2: cgpointmake (163.77, 71.76)]; [bezierpath addcurvetopoint: cgpointmake (170.01, 53.2) controlpoint1: cgpointmake (165.71, 66) controlpoint2: cgpointmake (169.06, 55.92)]; [bezierpath addcurvetopoint: cgpointmake (183.09, 29.29) controlpoint1: cgpointmake (174.54, 40.1) controlpoint2: cgpointmake (178.09, 33.17)]; [bezierpath addcurvetopoint: cgpointmake (207.73, 32.08) controlpoint1: cgpointmake (189.16, 24.57) controlpoint2: cgpointmake (196.99, 25.3)]; [bezierpath addcurvetopoint: cgpointmake (231.82, 80.54) controlpoint1: cgpointmake (224.41, 42.62) controlpoint2: cgpointmake (230.78, 57.67)]; [bezierpath addcurvetopoint: cgpointmake (231.98, 95.87) controlpoint1: cgpointmake (232.01, 84.84) controlpoint2: cgpointmake (232.03, 88.32)]; [bezierpath addcurvetopoint: cgpointmake (235.32, 127.15) controlpoint1: cgpointmake (231.86, 113.33) controlpoint2: cgpointmake (232.39, 120.2)]; [bezierpath addcurvetopoint: cgpointmake (259.98, 142) controlpoint1: cgpointmake (239.09, 136.1) controlpoint2: cgpointmake (246.69, 141.02)]; [bezierpath addcurvetopoint: cgpointmake (285.24, 127.17) controlpoint1: cgpointmake (272.35, 142.91) controlpoint2: cgpointmake (280.44, 137.75)]; [bezierpath addcurvetopoint: cgpointmake (291.02, 90.5) controlpoint1: cgpointmake (289.16, 118.51) controlpoint2: cgpointmake (290.78, 106.84)]; [bezierpath addcurvetopoint: cgpointmake (290.96, 74.58) controlpoint1: cgpointmake (291.09, 86.01) controlpoint2: cgpointmake (291.07, 82.22)]; [bezierpath addcurvetopoint: cgpointmake (292.11, 46.27) controlpoint1: cgpointmake (290.74, 57.91) controlpoint2: cgpointmake (290.89, 51.9)]; [bezierpath addcurvetopoint: cgpointmake (303.56, 39.05) controlpoint1: cgpointmake (293.74, 38.8) controlpoint2: cgpointmake (297.35, 36.18)]; [bezierpath addcurvetopoint: cgpointmake (320.2, 88.6) controlpoint1: cgpointmake (315.78, 44.7) controlpoint2: cgpointmake (320.73, 62.49)]; [bezierpath addcurvetopoint: cgpointmake (320,153) controlpoint1: cgpointmake (319.99, 99.31) controlpoint2: cgpointmake (320,153)]; [bezierpath addlinetopoint: cgpointmake (0,153)]; [bezierpath closepath]; return bezierpath;} @ end

You need to set the time to be consistent :)

 

 

 

 

 

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.