[英]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.