我从互联网上下载了动画篝火。我的图像序列是“* .png”,我无法使其工作。它一直循环到最后。它不显示图像。为什么我不能为这段代码制作动画?我做错了什么?
UIImageView* campFireView = [[UIImageView alloc] initWithFrame:screenx.frame];
int j;
int i;
for (j = 1, i = 0; i < 28; i =1)
{
NSLog( @"%i.png", i);
campFireView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:[NSString stringWithFormat:@"%i.png",i]], nil];
}
// all frames will execute in 1.75 seconds
campFireView.animationDuration = .15;
// repeat the annimation forever
campFireView.animationRepeatCount = 1;
// start animatinganimationRepeatCount:1];
[campFireView startAnimating];
// add the animation view to the main window
[self.view addSubview:campFireView];
[campFireView release];
答案 0 :(得分:1)
每次打电话:
campFireView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:[NSString stringWithFormat:@"%i.png",i]], nil];
您正在将animationImages
设置为单项数组。您可能打算做什么:
NSMutableArray *animationImages = [NSMutableArray array];
for (i = 0; i < 28; i++)
{
[animationImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%i.png",i]]];
}
campfireView.animationImages = animationImages;
另外 - 我不知道您的for
循环发生了什么,但我修复了它。
答案 1 :(得分:0)
当你循环播放然后每次为animationImages提供一个图像
NSMutableArray *arrImgs = [NSMutableArray array];
for (i = 0; i < 28; i++)
{
[arrImgs addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%i.png",i]]];
}
campfireView.animationImages = [NSArray arrayWithArray:arrImgs];