简体   繁体   English

在iPhone上使用UIImageView进行翻页动画

[英]Using UIImageView for a flipbook anim on iphone

I'm using UIImageView to run a flipbook anim like this: 我正在使用UIImageView运行这样的动画书动画:

mIntroAnimFrame = [[UIImageView alloc] initWithFrame:CGRectMake( 0, 0, 480, 320);
mIntroAnimFrame.image = [UIImage imageNamed:@"frame0000.tif"];

Basically, when determine it is time, I flip the image by just calling: 基本上,当确定时间到了,我通过调用以下命令翻转图像:

mIntroAnimFrame.image = [UIImage imageNamed:@"frame0000.tif"];

again with the right frame. 再次以正确的框架。 Should I be doing this differently? 我应该这样做吗? Are repeated calls to set the image this way possibly bogging down main memory, or does each call essentially free the previous UIImage because nothing else references it? 重复调用以这种方式设置图像可能会阻塞主内存,还是每个调用本质上都释放了先前的UIImage,因为没有其他东西引用它了? I suspect the latter is true. 我怀疑后者是真的。

Also, is there an easy way to preload the images? 另外,是否有一种简单的方法来预加载图像? The anim seems to slow down at times. 动画有时会变慢。 Should I simply load all the images into a dummy UIImage array so they are preloaded, then refer to it when I want to show it with mIntroAnimFrame.image = mPreloadedArray[i]; 我应该简单地将所有图像加载到虚拟UIImage数组中以进行预加载,然后在我想通过mIntroAnimFrame.image = mPreloadedArray [i]进行显示时引用它。 ?

I was typing up an example but remembered there was a perfect one at http://www.iphoneexamples.com/ 我正在输入示例,但记得在http://www.iphoneexamples.com/上有一个完美的示例

NSArray *myImages = [NSArray arrayWithObjects:
    [UIImage imageNamed:@"myImage1.png"],
    [UIImage imageNamed:@"myImage2.png"],
    [UIImage imageNamed:@"myImage3.png"],
    [UIImage imageNamed:@"myImage4.gif"],
    nil];

UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25; // seconds
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release]; 

Was this what you were thinking of? 这是您在想的吗?

[UIImage imageNamed:] will cache images, so they will not be immediately freed. [UIImage imageNamed:]将缓存图像,因此不会立即释放它们。 There is nothing wrong with that, but if you know you will not use the image again for a while, use a different method to get the images. 没什么问题,但是如果您知道一段时间后不会再次使用该图像,请使用其他方法来获取图像。

UIImageView also has built in animation abilities if you have a regular frame rate. 如果您具有固定的帧频,则UIImageView还具有内置的动画功能。

mIntroAnimFrame.animationImages = mPreloadedArray;
[mIntroAnimFrame startAnimating];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPhone-将NSCoder与UIImageView的子类一起使用 - iPhone - Using NSCoder with subclass of UIImageView 使用目标C为iPhone预加载UIImageView动画 - Preloading a UIImageView animation using objective c for the iphone iPhone SDK:如何使用CoreAnimation在UIImageView中设置一组图像动画? - iphone sdk: How to animate set of images in UIImageView using CoreAnimation? 使用UIImageView制作类似iPhone的Photo Galerry的应用 - Using UIImageView to make a app like iPhone's Photo Galerry iPhone使用UIImageView进行大量动画制作的最佳做​​法 - iPhone Best practices for large number of animations using UIImageView iPhone SDK从屏幕上删除UIImageView使用触摸? - iPhone SDK Erase A UIImageView from the Screen Using Touches? iPhone-使用CABasicAnimation进行动画时,UIImageView无法接收触摸事件 - iPhone - Touch event is not received by UIImageView while animating using CABasicAnimation 使用适用于iPhone的DropBox SDK从UIImageView上传图像 - Upload Image from UIImageView using DropBox SDK for Iphone 如何使用uiimageview修改图像中的像素并在iPhone中显示新图像? - How to modify the pixel in image using uiimageview and display the new image in iPhone? iPhone上的iPhone 4.0上的App使用的内存[Real RAM],然后使用UIImageview - Memory [ Real RAM ] used by App on IPhone 4.0 on lauch and then using UIImageview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM