objective c - CABasic doesn't rid of image after completing the animation -
i have button in nib file plays sound , calls method below.
-(void) animateheart { heartlayer = [[calayer alloc] init]; [heartlayer setbounds:cgrectmake(0.0, 0.0, 85.0, 85.0)]; [heartlayer setposition:cgpointmake(150.0, 100.0)]; uiimage *heartimage = [uiimage imagenamed:@"heart.png"]; cgfloat nativewidth = cgimagegetwidth(heartimage.cgimage) / 3; cgfloat nativeheight = cgimagegetheight(heartimage.cgimage) / 3; cgrect startframe = cgrectmake(165.0, 145.0, nativewidth, nativeheight); heartlayer.contents = (id)heartimage.cgimage; heartlayer.frame = startframe; [self.view.layer addsublayer:heartlayer]; cabasicanimation *theanimation; theanimation=[cabasicanimation animationwithkeypath:@"opacity"]; theanimation.duration=2.5; theanimation.repeatcount=2; theanimation.speed = 1.85; theanimation.autoreverses=yes; theanimation.timingfunction = [camediatimingfunction functionwithname: kcamediatimingfunctioneaseineaseout]; theanimation.fromvalue=[nsnumber numberwithfloat:0.0]; theanimation.tovalue=[nsnumber numberwithfloat:1.0]; [theanimation setvalue:heartlayer forkey:@"parentlayer"]; [heartlayer addanimation:theanimation forkey:@"animateopacity"]; theanimation.fillmode = kcafillmoderemoved; theanimation.removedoncompletion = yes; }
the method animates image fine after having done so, image left hanging there on view despite having set removedoncompletion bool true. have image disappear once animation has completed. i'd appreciate here.
thank in advance, so.
setting removedoncompletion
yes
ensures animation removed image's layer on completion, not image layer removed superlayer. need add delegate, track completion event, , call removefromsuperview
on view. implement - (void)animationdidstart:(caanimation *)theanimation
method on delegate, call [heartlayer removefromsuperlayer]
.
Comments
Post a Comment