我想在 NSImageView 中为 png 序列设置动画,但我无法使其工作。它只是不想显示任何动画。有什么建议吗?
这是我的代码:
- (void) imageAnimation {
NSMutableArray *iconImages = [[NSMutableArray alloc] init];
for (int i=0; i<=159; i++) {
NSString *imagePath = [NSString stringWithFormat:@"%@_%05d",@"clear",i];
[iconImages addObject:(id)[NSImage imageNamed:imagePath]];
//NSImage *iconImage = [NSImage imageNamed:imagePath];
//[iconImages addObject:(__bridge id)CGImageCreateWithNSImage(iconImage)];
}
CALayer *layer = [CALayer layer];
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
[animation setCalculationMode:kCAAnimationDiscrete];
[animation setDuration:10.0f];
[animation setRepeatCount:HUGE_VALF];
[animation setValues:iconImages];
[layer setFrame:NSMakeRect(0, 0, 104, 104)];
layer.bounds = NSMakeRect(0, 0, 104, 104);
[layer addAnimation:animation forKey:@"contents"];
//Add to the NSImageView layer
[iconV.layer addSublayer:layer];
}