2

次のコードを使用して、単純なCAKeyframeAnimationを作成しようとしています。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    CALayer *rotLayer = [CALayer layer];
    rotLayer.bounds = CGRectMake(0.0, 0.0, 100.0, 50.0);
    rotLayer.anchorPoint = CGPointMake(0.5, 0.5);
    rotLayer.position = CGPointMake(160.0, 200.0);
    rotLayer.backgroundColor = [UIColor redColor].CGColor;

    [self.view.layer addSublayer:rotLayer];

    /*
    CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    basic.duration = 3.0;
    basic.fromValue = [NSNumber numberWithFloat:0.0];
    basic.toValue = [NSNumber numberWithFloat:2.0];

    [rotLayer addAnimation:basic forKey:@"basic"];
    */

    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
    animation.duration = 3.0;
    animation.keyTimes = @[ [NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:1.0] ];
    animation.values = @[ [NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:2.0] ];
    animation.timingFunctions = @[ [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear] ];
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;

    [rotLayer addAnimation:animation forKey:@"test"];   
}

キーフレームの代わりに基本的なアニメーションを使用すると、すべてが期待どおりに機能しますが、このコードをシミュレーターで実行すると、次のメッセージが表示されてクラッシュします。

 -[CAKeyframeAnimation _copyRenderAnimationForLayer:]: unrecognized selector sent to instance 0x7558870
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CAKeyframeAnimation _copyRenderAnimationForLayer:]: unrecognized selector sent to instance 0x7558870'

これはARC対応の新しいプロジェクトです。アニメーションをプロパティとして設定しても機能しません。QuartzCoreフレームワークもリンクです。私は何が間違っていますか?

4

1 に答える 1

2

このコードを実行すると、問題なく機能します(長方形の中心にあるアンカーポイントを中心に赤い長方形が回転します)。

QuartzCoreフレームワークを適切にリンクしましたか?<QuartzCore/QuartzCore.h>そして、実装ファイルにインポートしましたか?Appleの内部メソッドのように見える_copyRenderAnimationForLayer:ので、その存在に疑問はありません。ただし、ファイルを適切にリンクまたはインポートしていない場合、アプリケーションはそのメソッドが存在することを認識せず、表示されている例外をスローします。

于 2012-12-21T17:57:42.367 に答える