0

我有一个 UIImageView,我正在尝试制作一组​​ UIImages 的动画,这些 UIImages 是通过翻转其他 UIImages 创建的。这是我的代码:

    turtle = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width-200,
                                                                    self.view.frame.size.height - sand.frame.size.height - turtle.frame.size.height - 10 - heightOfKeyboard,
                                                                    100,100)];
[flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle1.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]];
[flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle2.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]];
[flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle3.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]];
[flippedTurtleArray addObject:[UIImage imageWithCGImage:[UIImage imageNamed:@"Turtle2.png"].CGImage scale:1 orientation:UIImageOrientationDownMirrored]];
[self.view addSubview: turtle];

问题是,当我尝试从翻转图像数组中对其进行动画处理时,它会显示原始图像,而不是翻转图像(即,当我这样做时):

turtle.animationImages = flippedTurtleArray;
turtle.animationDuration = 0.8f;
turtle.animationRepeatCount = 0;
[turtle startAnimating];

显示原始的非翻转图像。

现在,如果我这样做:

turtle.image = [flippedTurtleArray objectAtIndex:1];

显示翻转的图像。我想也许你不能用 CGImage 做动画,但找不到其他人有同样的问题。有任何想法吗?

谢谢,

山姆

4

1 回答 1

0

我会查看 CGLayer 属性,特别是图层的变换属性。

Transform 属性是可动画的,允许您对原始图像应用任意变换,而无需管理中间翻转的 Turtle Array。

应用于图层内容的变换。动画。

@property CATransform3D 转换讨论此属性默认设置为身份转换。您对图层应用的任何变换都相对于图层的锚点发生。

可用性 适用于 iOS 2.0 及更高版本。在 CALayer.h 中声明的相关示例代码 oalTouch

如果您有其他需要该数组的原因,那么您可能希望将翻转的图像渲染为单独的图像,并将其传递到您的数组中。

同样,如果您可以使用 iOS 7 作为目标,看看 SpriteKit,它可能会使整个任务变得更加简单。

于 2013-10-06T21:56:03.873 回答