我一直在努力做CALayer
动画。 但动画完成后,它会恢复,背部装有发现了一些解决方案,如removedOnCompleteion = YES
和fill mode = kCAFillModesForwards
但都不是我的帮助。 这里是代码。 需要一点点帮助家伙THX。
void(^ myblock)(NSDictionary *) = ^(NSDictionary *dict){
NSMutableArray *arrOfPt= [dict objectForKey:@"Path"];
CGPoint p1 = [[arrOfPt objectAtIndex:0] CGPointValue];
CGPoint cp1 = [[arrOfPt objectAtIndex:1] CGPointValue];
// CGPoint cp1 = [[arrOfPt objectAtIndex:1] CGPointValue];
CGPoint cp2 = [[arrOfPt objectAtIndex:2] CGPointValue];
CGPoint p2 = [[arrOfPt objectAtIndex:3] CGPointValue];
NSMutableArray *arrayTime = [dict objectForKey:@"Time"];
CGFloat time = [[arrayTime objectAtIndex:0] floatValue];
pointerLayer.opacity = 1;
// NSArray *oneObjPt = [NSArray arrayWithObjects:[arrOfPt objectAtIndex:0],[arrOfPt lastObject],nil];
// NSArray *oneObjTime = [NSArray arrayWithObjects:[arrayTime objectAtIndex:0],[arrayTime lastObject],nil];
// NSArray *oneObjTime = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],[NSNumber numberWithFloat:1.0],nil];
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
// [keyFrameAnimation setCalculationMode:kCAAnimationPaced];
keyFrameAnimation.duration = 1;
keyFrameAnimation.removedOnCompletion = NO;
[keyFrameAnimation setFillMode:kCAFillModeForwards];
CGMutablePathRef fpath = CGPathCreateMutable();
CGPathMoveToPoint(fpath, NULL, p1.x, p1.y);
CGPathAddCurveToPoint(fpath, NULL, cp1.x, cp1.y, cp2.x, cp2.y, p2.x, p2.y);
keyFrameAnimation.path = fpath;
[pointerLayer addAnimation:keyFrameAnimation forKey:@"pos"];
CGPoint newLoc = pointerLayer.position;// this is just to verify the layer's location