如何为一组图像设置动画? [英] how to animate a set of images?
问题描述
如何为一组图像制作动画,但是我有大量的图像,准确地说是300张,
how to animate a set of images, but I have a large set of images, 300 to be exact,
Background.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"001.jpg"],
[UIImage imageNamed:@"002.jpg"],
[UIImage imageNamed:@"003.jpg"],
[UIImage imageNamed:@"004.jpg"],
[UIImage imageNamed:@"005.jpg"],
[UIImage imageNamed:@"006.jpg"],
[UIImage imageNamed:@"007.jpg"],
[UIImage imageNamed:@"008.jpg"],
[UIImage imageNamed:@"009.jpg"],
[UIImage imageNamed:@"010.jpg"],
nil];
而且我不想一路输入到300,这是否有解决方案? 我可以为此使用循环吗?
and I dont wanna go all the way up to 300 by typing, is there a solution for this? Could I use a loop for this?
推荐答案
一个循环可能看起来像这样
A loop might look like this
NSMutableArray *animationImages = [[NSMutableArray alloc] initWithCapacity:300];
for (int i = 1; i <= 300; i++) {
NSString *imageName = [NSString stringWithFormat:@"%03d.jpg", i];
[animationImages addObject:[UIImage imageNamed:imageName]];
}
Background.animationImages = animationImages;
格式说明符%03d
表示用0填充的整数,以使最小字段宽度为3.
The format specifier %03d
means an integer padded with 0's to give a minimum field width of 3.
但
根据图像的大小,您可能会耗尽内存并终止应用程序.
depending on the size of your images you may well run out of memory and have your app terminated.
Background
对于Objective-C上的变量不是一个很好的名字.约定是使用小写字母开头的变量名,然后在其后使用驼峰大小写.
Background
is not a very good name for a variable on Objective-C. The convention is to start variable names with a lowercase letter and then use camel case after that.
这篇关于如何为一组图像设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!