0

パス(線形パス)を通過する限りビューを回転させようとしますが、回転しません。

これは私のコードです:

 CAKeyframeAnimation *animKF = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animKF.values = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(100, 100)], [NSValue valueWithCGPoint:CGPointMake(400, 400)], [NSValue valueWithCGPoint:CGPointMake(700, 100)], [NSValue valueWithCGPoint:CGPointMake(1000, 400)], nil];

animKF.keyTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.25], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:1.0], nil];

animKF.duration = 6;

animKF.rotationMode =  kCAAnimationRotateAuto;

[imageView.layer addAnimation:animKF forKey:@"keyframe"];

ただし、imageView(画像の青い面)はパス(画像の赤い線)に沿って回転しません

道

どうもありがとう。

4

1 に答える 1

2

From the documentation of rotationMode:

The effect of setting this property to a non-nil value when no path object is supplied is undefined.

In your code you are setting the values-property of your key frame animation but you need to set a path instead.


You should create a CGPath from your values and set that as the path of your keyframe.

UIBezierPath *animationPath = [UIBezierPath bezierPath];
[animationPath moveToPoint:CGPointMake(100, 100)];
[animationPath addLineToPoint:CGPointMake(400, 400)];
[animationPath addLineToPoint:CGPointMake(700, 100)];
[animationPath addLineToPoint:CGPointMake(1000, 400)];

animKF.path = animationPath.CGPath;
于 2012-12-04T09:21:56.017 に答える