0
我想要使用核心動畫製作紋理包裝器製作的精靈表。CAKeyframeAnimation雪碧動畫
我有一個NSCollection與我所有的精靈內容。 (鍵和CGImageRef的)
My Collection {
"caja01.png" = "<UIImage: 0x1cda57c0>";
"caja02.png" = "<UIImage: 0x1cda61d0>";
"caja03.png" = "<UIImage: 0x1cda62e0>";
"caja04.png" = "<UIImage: 0x1cda63f0>";
"caja05.png" = "<UIImage: 0x1cda6540>";
"caja06.png" = "<UIImage: 0x1cda6650>";
"caja07.png" = "<UIImage: 0x1cda6760>";
"caja08.png" = "<UIImage: 0x1cda68f0>";
}
,我嘗試使用CAKeyframeAnimation動畫:
NSArray *values = [self.mySprites allValues]; // Get the CGImageRef's from NSDictionary
// Creating a new layer
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor blueColor].CGColor;
sublayer.frame = imagen.frame;
[self.view.layer addSublayer:sublayer];
// Create an first image from Sprite-sheet
UIImageView *imagen = [[UIImageView alloc]initWithImage:[self.mySprites objectForKey:@"caja01.png"]];
// And add initial content to my layer
sublayer.contents = (id) imagen.image.CGImage;
// Try to make the animation
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath: @"contents"];
animation.calculationMode = kCAAnimationDiscrete;
animation.duration = 10.0;
[animation setValues:values];
[animation setRepeatCount:2];
[animation setRemovedOnCompletion:NO];
[sublayer addAnimation: animation forKey: @"contents"];
但它不工作,沒有任何反應在屏幕上。有什麼建議麼?謝謝!
爲什麼不使用帶有animationImages的UIImageView? – 2013-04-10 11:08:05
哎唷!我不知道它存在!謝謝,我會調查;) – 2013-05-28 15:38:42