2

我从网上下载了动画篝火。我的图像序列是“*.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]; 
4

2 回答 2

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循环发生了什么,但我修复了它。

于 2012-09-25T05:49:22.763 回答
0

当您循环时,每次向动画图像提供一张图像

NSMutableArray *arrImgs = [NSMutableArray array];

for (i = 0; i < 28; i++)
    {
        [arrImgs addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%i.png",i]]];
    }

campfireView.animationImages  = [NSArray arrayWithArray:arrImgs];
于 2012-09-25T05:51:28.050 回答