首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >雪碧图动画的CAKeyframeAnimation

雪碧图动画的CAKeyframeAnimation
EN

Stack Overflow用户
提问于 2013-04-10 18:32:35
回答 1查看 379关注 0票数 1

我正在尝试动画与纹理包装器使用核心动画的精灵工作表。

我有一个包含所有精灵内容的NSCollection。(密钥和CGImageRef)

代码语言:javascript
复制
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来做动画:

代码语言:javascript
复制
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"];

但是它不起作用,屏幕上什么也没发生。有什么建议吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-13 03:19:04

我的建议是“不要那样做”。您正在尝试实现一种技术,精灵工作表,用于解决与核心动画无关的问题。

使用sprite sheets的原因是为了处理OpenGL (和其他图形API)中的内存管理问题。核心动画的工作方式不同,因此在CA中实现精灵工作表动画不是一个很好的选择。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15923399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档