在 iPhone 上使用 UIImageView 制作翻页动画

发布于 2024-09-02 07:52:16 字数 572 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三生殊途 2024-09-09 07:52:16

我正在输入一个示例,但记得 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]; 

这就是你的想法吗?

I was typing up an example but remembered there was a perfect one at 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?

我不在是我 2024-09-09 07:52:16

[UIImage imageNamed:] 将缓存图像,因此它们不会立即释放。这没有什么问题,但如果您知道一段时间内不会再次使用该图像,请使用不同的方法来获取图像。

如果您有常规的帧速率,UIImageView 还具有内置动画功能。

mIntroAnimFrame.animationImages = mPreloadedArray;
[mIntroAnimFrame startAnimating];

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

mIntroAnimFrame.animationImages = mPreloadedArray;
[mIntroAnimFrame startAnimating];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文