在 iPhone 上使用 UIImageView 制作翻页动画
我正在使用 UIImageView 来运行这样的翻页动画:
mIntroAnimFrame = [[UIImageView alloc] initWithFrame:CGRectMake( 0, 0, 480, 320);
mIntroAnimFrame.image = [UIImage imageNamed:@"frame0000.tif"];
基本上,当确定时间到了时,我只需调用即可翻转图像:
mIntroAnimFrame.image = [UIImage imageNamed:@"frame0000.tif"];
再次使用正确的框架。我应该采取不同的做法吗?重复调用以这种方式设置图像是否可能会导致主内存陷入困境,或者每次调用实际上都会释放前一个 UIImage 因为没有其他东西引用它?我怀疑后者是真的。
另外,有没有一种简单的方法来预加载图像?动画有时似乎会变慢。我是否应该简单地将所有图像加载到虚拟 UIImage 数组中以便预加载它们,然后在我想使用 mIntroAnimFrame.image = mPreloadedArray[i]; 显示它时引用它?
I'm using UIImageView to run a flipbook anim like this:
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? 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]; ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在输入一个示例,但记得 http://www.iphoneexamples.com/
这就是你的想法吗?
I was typing up an example but remembered there was a perfect one at http://www.iphoneexamples.com/
Was this what you were thinking of?
[UIImage imageNamed:] 将缓存图像,因此它们不会立即释放。这没有什么问题,但如果您知道一段时间内不会再次使用该图像,请使用不同的方法来获取图像。
如果您有常规的帧速率,UIImageView 还具有内置动画功能。
[UIImage imageNamed:] will cache images, so they will not be immediately freed. 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.