1

CALayer私はアニメーションをやろうとしてきました。しかし、アニメーションの後、それは元に戻ります.andのようないくつかの解決策を見つけましたremovedOnCompleteion = YESfill mode = kCAFillModesForwards、どれも私を助けてくれません. これがコードです。少し助けが必要です。

  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
4

2 に答える 2

1

I found a few solutions like removedOnCompleteion = YES and fill mode = kCAFillModesForwards

Those are not solutions.

CGPoint newLoc = pointerLayer.position;

That won't do any good; adding an animation does not actually change the position. The animation happens later.

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.

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

于 2013-04-04T13:34:24.167 に答える
0

これを再現できないようです-いくつかのテストデータを使用したことを認めます:

CGPoint cp1 = CGPointMake(0, 0);
CGPoint cp2 = CGPointMake(100, 100);
CGPoint cp3 = CGPointMake(85, 150);
CGPoint cp4 = CGPointMake(50, 50);
CGFloat time = 2.0f;
CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyFrameAnimation.duration = time;
keyFrameAnimation.removedOnCompletion = NO;
[keyFrameAnimation setFillMode:kCAFillModeForwards];

CGMutablePathRef fpath = CGPathCreateMutable();

CGPathMoveToPoint(fpath, NULL, cp1.x, cp1.y);
CGPathAddCurveToPoint(fpath, NULL, cp2.x, cp2.y, cp3.x, cp3.y, cp4.x, cp4.y);
keyFrameAnimation.path = fpath;
[testView.layer addAnimation:keyFrameAnimation forKey:@"pos"];
CFRelease(fpath);

出力:

http://glassofcocoa.com/code/AnimationTest.mp4

配列内のポイントの 1 つが開始位置になる可能性がありますか?

于 2013-04-04T13:26:37.637 に答える