播放一次 UIImageView 动画并在播放后立即将其从内存中删除的最佳方法是什么?
我很难从记忆中删除我的动画。最好的方法是什么?
这是我的动画代码:
-(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Xcode 4.2下不需要再用ARC发布了!今天更新:)
Don't need to release it anymore with ARC under Xcode 4.2! Update today :)
据我所知,没有回调可以知道 imageView 的动画何时完成。这是不幸的,因为这意味着要在 imageView 完成动画时删除动画,您将需要重复检查 imageView 的
isAnimating
方法,直到它返回 false。以下是我的意思的一个示例:您也许能够执行类似的操作 - 在原始代码中添加以下行
然后创建一个方法
这只是一个示例,我使用了值 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
Then create a method
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.