CALayer动画还原 [英] CALayer animation reverts
问题描述
我一直在尝试制作 CALayer
动画。但是在动画之后它又恢复了原样。我发现了一些解决方案,例如 removedOnCompleteion = YES
和 fill mode = kCAFillModesForwards
,但是没有一个解决方案帮我。这是代码。
I have been trying to do CALayer
animation. But after animation it reverts back.I found a few solutions like removedOnCompleteion = YES
and fill mode = kCAFillModesForwards
but none is helping me. here is the code. Need a little help fellows 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
推荐答案
我发现了一些解决方案,例如removeOnCompleteion = YES和填充模式= kCAFillModesForwards
I found a few solutions like removedOnCompleteion = YES and fill mode = kCAFillModesForwards
这些不是解决方案。
CGPoint newLoc = pointerLayer.position;
CGPoint newLoc = pointerLayer.position;
那不会有什么好处;添加动画实际上并不会改变位置。动画发生在以后。
That won't do any good; adding an animation does not actually change the position. The animation happens later.
我不确定您想要什么,但是它可能有助于您阅读我对Core的解释动画。动画只是一种幻想;这是带有表示层的游戏。由 you 决定将 real 图层移动到动画之后的位置,然后将添加到动画中。让它移动到那里。
I'm not entirely sure what you're after, but it might help you to read my explanation of Core Animation. Animation is just an illusion; it's a game played with the "presentation layer". It is up to you to move the real layer to where it is going to be after the animation and to add the animation that will appear to make it move there.
我提供了一种确定性的方法来确保您的Core Animation可以使您到达想要去的地方:
I provide a formulaic approach for making sure that your Core Animation works to get you where you want to go:
http://www.apeth.com/iOSBook/ch17。 html#_using_a_cabasicanimation
这篇关于CALayer动画还原的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!