播放一次 UIImageView 动画并在播放后立即将其从内存中删除的最佳方法是什么?

发布于 2024-12-10 13:09:27 字数 603 浏览 5 评论 0原文

我很难从记忆中删除我的动画。最好的方法是什么?

这是我的动画代码:

-(IBAction)animationOneStart { 

NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:88];

for(int count = 1; count <= 88; count++)
{
NSString *fileName = [NSString stringWithFormat:@"testPic1_%03d.jpg", count];
UIImage  *frame    = [UIImage imageNamed:fileName];
[images addObject:frame];
}

loadingImageView.animationImages = images;

loadingImageView.animationDuration = 5;
loadingImageView.animationRepeatCount = 1; //Repeats indefinitely

[loadingImageView startAnimating];
[images release];

}

谢谢!

I'm having a hard time removing my animation from memory. What is the best way to do this?

This is my animation code:

-(IBAction)animationOneStart { 

NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:88];

for(int count = 1; count <= 88; count++)
{
NSString *fileName = [NSString stringWithFormat:@"testPic1_%03d.jpg", count];
UIImage  *frame    = [UIImage imageNamed:fileName];
[images addObject:frame];
}

loadingImageView.animationImages = images;

loadingImageView.animationDuration = 5;
loadingImageView.animationRepeatCount = 1; //Repeats indefinitely

[loadingImageView startAnimating];
[images release];

}

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

や莫失莫忘 2024-12-17 13:09:27
[images removeAllObjects];
[images release];
[images removeAllObjects];
[images release];
雾里花 2024-12-17 13:09:27

Xcode 4.2下不需要再用ARC发布了!今天更新:)

Don't need to release it anymore with ARC under Xcode 4.2! Update today :)

旧伤慢歌 2024-12-17 13:09:27

据我所知,没有回调可以知道 imageView 的动画何时完成。这是不幸的,因为这意味着要在 imageView 完成动画时删除动画,您将需要重复检查 imageView 的 isAnimating 方法,直到它返回 false。以下是我的意思的一个示例:

您也许能够执行类似的操作 - 在原始代码中添加以下行

[loadingImageView startAnimating];
[images release];

[self performSelector:@selector(checkIfAnimationIsFinished) withObject:nil afterDelay:4.5f];

然后创建一个方法

-(void)checkIfAnimationIsFinished {
    if (![loadingImageView isAnimating]) {
        [loadingImageView release];
    } else {
        [self performSelector:@selector(checkIfAnimationIsFinished) withObject:nil afterDelay:0.5f];
    }
}

这只是一个示例,我使用了值 4.5f 和 0.5f,因为,不幸的是,这个时间并不精确,更多的是一个大概的数字。 4.9f 和 0.1f 可能效果更好。无论如何,问题是,如果您将方法设置为在开始动画后 5.0f 秒触发,则不能 100% 确定动画是否完成。所以如果没有完成,你需要反复检查。

无论如何,这不是最干净的解决方案,但除非其他人知道如何在 imageView 完成动画处理时获取回调,否则我不知道更好的解决方案。

As far as I can tell, there is not a callback to know when the imageView's animation is finished. This is unfortunate, because it means that to remove the animation when the imageView is finished animating, you will need repeatedly check the imageView's isAnimating method until it returns false. The following is an example of what I mean:

You might be able to do something like this—in your original code, add the following line

[loadingImageView startAnimating];
[images release];

[self performSelector:@selector(checkIfAnimationIsFinished) withObject:nil afterDelay:4.5f];

Then create a method

-(void)checkIfAnimationIsFinished {
    if (![loadingImageView isAnimating]) {
        [loadingImageView release];
    } else {
        [self performSelector:@selector(checkIfAnimationIsFinished) withObject:nil afterDelay:0.5f];
    }
}

This was just an example, I used the values 4.5f and 0.5f because, unfortunately, the timing is not precise, it is more of a ballpark figure. 4.9f and 0.1f might work better. Regardless, the problem is that if you set the method to fire 5.0f seconds after you start the animation, it is not 100% certain that the animation will be be finished or not. So you will need to check repeatedly if it is not finished.

Anyway, this is not the cleanest solution, but unless someone else knows how to get a callback when an imageView is finished animating, I don't know of a better solution.

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