对于动画iPhone上的图像(如电影),而无需使用MPMoviePlayer方法 [英] Method for animating images (like a movie) on iPhone without using MPMoviePlayer

查看:127
本文介绍了对于动画iPhone上的图像(如电影),而无需使用MPMoviePlayer方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够在一个静态图像显示动画。

I need to be able to display an animation over a static image.

,我能想到的唯一办法做到这一点是使用多个静态图像,这是我们展示(一个接一个)来创建一个电影像动画。

Given that MPMoviePlayer gives you no control over anything useful, the only way I can think to do this is to use multiple static images, which we display (one-by-one) to create a "movie like" animation.

我知道我们可以使用的UIImageView做到这一点(通过设置UIImageView的 animationImages 属性,然后调用 startAnimation ),但我们将有超过100个图像,我们动画 - 这么内存使用情况将被刷爆了。

I know we could use UIImageView to do this (by setting the UIImageView animationImages property and then calling startAnimation), however we are going to have over 100 images in our animation - so memory usage will be maxed out.

没有人有任何好的方法可以做到这种动画?使用核心动画或OpenGL?

Does anyone have any nice ways to do this kind of animation? Using Core Animation or OpenGL?

我的猜测是,我们需要创建一个图像缓冲区,当我们加载新的图像,我们从图像缓冲区??

My guess is that we'd need to create an image buffer, and as we load new images, we display images from the image buffer??

推荐答案

您可以使用一个核心动画CALayer的托管您的动画,并指出,主层的交换一系列CALayers来执行你的帧一帧动画。您可以使用其内容属性设置一个图像帧主办的CALayer的一个CGImageRef的内容。可以在一个NSMutableArray被创建并存储了一系列含图像CALayers的需要,然后做的时候,以减少内存使用中删除。

You could use a Core Animation CALayer to host your animation, and swap a series of CALayers in and out of that main layer to perform your frame-by-frame animation. You can set the content of an image-frame-hosting CALayer to a CGImageRef using its contents property. A series of CALayers containing your images could be created and stored in an NSMutableArray as needed, then removed when done to minimize memory use.

您可以通过包装replaceSublayer设置帧之间的转换时间

You can set the transition duration between frames by wrapping the replaceSublayer:with: method call in a CATransaction, like the following:

[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:0.25f] // 1/4th of a second per frame
    		     forKey:kCATransactionAnimationDuration];	
[mainLayer replaceSublayer:[imageLayers objectAtIndex:oldImageIndex] with:[imageLayers objectAtIndex:newImageIndex]];
[CATransaction commit];

您可能还能够与交换进出CGImageRef在主层的内容,如果你的帧显示的时间很短,脱身。

You might also be able to get away with swapping in and out the CGImageRef in the contents of your main layer, if your frame display time is short enough.

这篇关于对于动画iPhone上的图像(如电影),而无需使用MPMoviePlayer方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆