动画在iPhone上 - 使用图像序列或循环? [英] Animation on the iPhone - use image sequence or rotation?

查看:178
本文介绍了动画在iPhone上 - 使用图像序列或循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造了我的iPhone应用程序很简单的动画。我有一个选择2种不同类型的动画之间进行。我可以用这...


 的NSArray * myImages = [NSArray的arrayWithObjects:
[UIImage的imageNamed:@myImage1.png],
[UIImage的imageNamed:@myImage2.png],
[UIImage的imageNamed:@myImage3.png],
[UIImage的imageNamed:@myImage4.gif],无]*的UIImageView = myAnimatedView [UIImageView的页头];
[myAnimatedView initWithFrame:方法[自我界限]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25;
[个体经营addSubview:myAnimatedView];
[myAnimatedView发布]


或者这样的事情...

  [UIView的beginAnimations:无背景:NULL];
 [UIView的setAnimationDuration:1.5];
 //其他动画到这里
 myImage.transform = CGAffineTransformMakeRotation(M_PI * 0.5);
 //其他动画到这里
 [UIView的commitAnimations];

我有好几个这些部件的动画,所以我想选择它使用的内存量最小,runds最快的一个选项。任何意见将是巨大的,谢谢


解决方案

所以,你需要考虑的根本问题是动画的多少帧你期望能够在内存中的时间。如果在一个使用animationImagesArray或一个单一的巨大图像与所有的帧也没关系。在内存持有德codeD映像数据占用了大量的空间,你也许能够逃脱它为少数的小图像,但你可以很容易地写一些code,它会崩溃,你的设备由于使用了所有的记忆。看到这个具体问题的视频和内存使用上,iOS设备。一个更好的方式来写你的code是根本就没有在同一时间保留在内存中的视频都去codeD帧(UIImages或CGImageRefs)。

I am creating a basic animation for my iPhone app. I have a choice to make between 2 different types of animation. I can use this...

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;  
[self addSubview:myAnimatedView]; 
[myAnimatedView release];

or something like this...

    [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:1.5];
 // other animations goes here
 myImage.transform = CGAffineTransformMakeRotation(M_PI*0.5);
 // other animations goes here
 [UIView commitAnimations];

I have quite a few of these parts to animate so I want to choose an option which uses the least amount of memory and runds the quickest. Any advice would be great, thanks

解决方案

So, the root issue that you need to consider is how many frames of animation you expect to be in memory at one time. It does not matter if you use the animationImagesArray or one single huge image with all the frames in one. Holding the decoded image data in memory takes up a lot of space, you might be able to get away with it for a small number of small images, but you could easily write some code that will crash you device due to using up all the memory. See my blog post about this specific issue video-and-memory-usage-on-ios-devices. A better way to write your code is to simply not hold all the decoded frames of video (UIImages or CGImageRefs) in memory at the same time.

这篇关于动画在iPhone上 - 使用图像序列或循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆