【问题标题】:UIImageView won't animate with UIImages of CGImageUIImageView 不会使用 CGImage 的 UIImages 进行动画处理
【发布时间】:2013-10-06 21:07:47
【问题描述】:

我有一个 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 做动画,但找不到其他人有同样的问题。有什么想法吗?

谢谢,

山姆

【问题讨论】:

    标签: objective-c animation uiimageview uiimage cgimage


    【解决方案1】:

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

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

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

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

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

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

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

    【讨论】:

    • 嗨 - 我将如何将翻转的图像渲染成单独的图像?我看不到该怎么做?
    • 啊好吧 - 明白了 - 我改变了方法,刚刚发现如何翻转实际的图像数据而不是标志。还是谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多