ios - Animating UIBezierPath in custom UIView doesn't work -


i trying animate uibezierpath (from 1 path another)) in custom uiview when user touches view (touchesended .

my drawing code:

- (void)drawrect:(cgrect)rect { // drawing code [self createstartpath]; [self createendpath];  cgcontextref currentcontext = uigraphicsgetcurrentcontext(); cgcontextaddpath(currentcontext, _startpath.cgpath); cgcontextdrawpath(currentcontext, kcgpathstroke);  }  - (void) createstartpath { _startpath = uibezierpath.bezierpath; [_startpath movetopoint: cgpointmake(18, 22.5)]; [_startpath addcurvetopoint: cgpointmake(18.38, 22.32) controlpoint1: cgpointmake(18.14, 22.5) controlpoint2: cgpointmake(18.29, 22.44)]; [_startpath addcurvetopoint: cgpointmake(18.32, 21.62) controlpoint1: cgpointmake(18.56, 22.11) controlpoint2: cgpointmake(18.53, 21.79)]; [_startpath addlinetopoint: cgpointmake(6.78, 12)]; [_startpath addlinetopoint: cgpointmake(18.32, 2.38)]; [_startpath addcurvetopoint: cgpointmake(18.38, 1.68) controlpoint1: cgpointmake(18.53, 2.21) controlpoint2: cgpointmake(18.56, 1.89)]; [_startpath addcurvetopoint: cgpointmake(17.68, 1.62) controlpoint1: cgpointmake(18.21, 1.47) controlpoint2: cgpointmake(17.89, 1.44)]; [_startpath addlinetopoint: cgpointmake(5.68, 11.62)]; [_startpath addcurvetopoint: cgpointmake(5.5, 12) controlpoint1: cgpointmake(5.56, 11.71) controlpoint2: cgpointmake(5.5, 11.85)]; [_startpath addcurvetopoint: cgpointmake(5.68, 12.38) controlpoint1: cgpointmake(5.5, 12.15) controlpoint2: cgpointmake(5.56, 12.29)]; [_startpath addlinetopoint: cgpointmake(17.68, 22.38)]; [_startpath addcurvetopoint: cgpointmake(18, 22.5) controlpoint1: cgpointmake(17.77, 22.46) controlpoint2: cgpointmake(17.89, 22.5)]; [_startpath closepath];  [self.fillcolor setfill];  [_startpath fill]; }  - (void) createendpath {  _endpath = uibezierpath.bezierpath; [_endpath movetopoint: cgpointmake(6, 22.5)]; [_endpath addcurvetopoint: cgpointmake(5.62, 22.32) controlpoint1: cgpointmake(5.86, 22.5) controlpoint2: cgpointmake(5.71, 22.44)]; [_endpath addcurvetopoint: cgpointmake(5.68, 21.62) controlpoint1: cgpointmake(5.44, 22.11) controlpoint2: cgpointmake(5.47, 21.79)]; [_endpath addlinetopoint: cgpointmake(17.22, 12)]; [_endpath addlinetopoint: cgpointmake(5.68, 2.38)]; [_endpath addcurvetopoint: cgpointmake(5.62, 1.68) controlpoint1: cgpointmake(5.47, 2.21) controlpoint2: cgpointmake(5.44, 1.89)]; [_endpath addcurvetopoint: cgpointmake(6.32, 1.62) controlpoint1: cgpointmake(5.79, 1.47) controlpoint2: cgpointmake(6.11, 1.44)]; [_endpath addlinetopoint: cgpointmake(18.32, 11.62)]; [_endpath addcurvetopoint: cgpointmake(18.5, 12) controlpoint1: cgpointmake(18.44, 11.71) controlpoint2: cgpointmake(18.5, 11.85)]; [_endpath addcurvetopoint: cgpointmake(18.32, 12.38) controlpoint1: cgpointmake(18.5, 12.15) controlpoint2: cgpointmake(18.44, 12.29)]; [_endpath addlinetopoint: cgpointmake(6.32, 22.38)]; [_endpath addcurvetopoint: cgpointmake(6, 22.5) controlpoint1: cgpointmake(6.23, 22.46) controlpoint2: cgpointmake(6.11, 22.5)]; [_endpath closepath];  [self.fillcolor setfill];  //[_endpath fill]; } 

i start animation here (would "morph" 1 path another):

- (void)touchesended:(nsset *)touches withevent:(uievent *)event  {     [super touchesended:touches withevent:event];      cashapelayer * mylineshapelayer = [[cashapelayer alloc] init];      cabasicanimation * pathanimation = [cabasicanimation animationwithkeypath:@"path"];     pathanimation.fromvalue = (__bridge id)[_startpath cgpath];     pathanimation.tovalue = (__bridge id)[_endpath cgpath];     pathanimation.duration = 3.0f;     [mylineshapelayer addanimation:pathanimation forkey:@"animationkey"]; } 

i see startpath , touchesended called, nothing animates neither endpath shown.

for animation work, please add mylineshapelayer sublayer of view's layer:

for instance, in viewdidload:

[self.view.layer addsublayer:mylineshapelayer]; 

in order able see endpath still being persistently seen on screen after animation, first assign endpath path property of cashapelayer:

mylineshapelayer.path = [endpath cgpath]; 

and thusly animate without tovalue:

cabasicanimation * pathanimation = [cabasicanimation animationwithkeypath:@"path"]; pathanimation.fromvalue = (__bridge id)[_startpath cgpath]; pathanimation.duration = 3.0f; [mylineshapelayer addanimation:pathanimation forkey:@"animationkey"]; 

the end effect of animation remain on screen after animation.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -