3
我想动画的图像序列,这可以很容易地完成与简单的UIImageView动画;不过,我希望能够检测动画何时完成,以便我可以允许用户执行另一项任务。所以我试图用CAKeyframeAnimation来做到这一点。当我运行以下代码时,程序崩溃了。有人能告诉我我做错了什么吗?使用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];
这可能会崩溃,因为您将值设置为'UIImage'而不是'CGImageRef'这是'contents'属性所需的值。 –