3

一連の画像をアニメーション化しようとしていますが、これは単純な UIImageView アニメーションで簡単に実行できます。ただし、アニメーションがいつ終了したかを検出できるようにして、ユーザーが別のタスクを実行できるようにしたいと考えています。だから私はCAKeyframeAnimationでそれをやろうとしていました. 次のコードを実行すると、プログラムがクラッシュしました。誰かが私が間違ったことを教えてもらえますか?

CALayer *myLayer = [[CALayer alloc]init];
   [myLayer setBounds:CGRectMake(0, 0, 100, 100)];
   [myLayer setPosition:CGPointMake(160.0, 100.0)];
    myLayer.backgroundColor = [[UIColor colorWithRed:4 green:0 blue:0 alpha:1] CGColor];
    [self.window.layer addSublayer:myLayer];

    CAKeyframeAnimation *anim;
    NSArray *images =[NSArray arrayWithObjects:[UIImage imageNamed:@"img1.png"],
                             [UIImage imageNamed:@"img2.png"],nil];  

    anim = [CAKeyframeAnimation animation];
    [anim setKeyPath:@"contents"];
    [anim setValues:images];
    [anim setCalculationMode:@"discrete"];
    [anim setRepeatCount:3];
    [anim setDuration:1.0];
    [myLayer addAnimation:anim forKey:nil];
4

1 に答える 1

0

あなたが言うように、単純な UIView アニメーションで実行できる場合は、実際に完了を確認できます。

[UIView animateWithDuration:duration
                 animations:^(void) {
                     ...
                 }
                 completion:^(BOOL finished) {
                     ...
                 }
 ];

なんらかの理由でそれができない場合は、クラッシュ レポートを確認すると便利です。

于 2011-11-28T22:24:09.933 に答える