ios - 动画 For 循环图像不显示

标签 ios xcode loops for-loop jquery-animate

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

最佳答案

每次调用:

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

关于ios - 动画 For 循环图像不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12576693/

相关文章:

ios - 将JSON响应分配给模型SwiftUI

ios - CFDictionary 更新到 PHPhotoLibrary kCGImagePropertyExifDictionary 不采取

iphone - 在 iphone 中为固定长度的数据样本创建频谱图

xcode - 如何让 xcodebuild 忽略错误

javascript - 如何打印出 3 的倍数除以无余数的数字?

javascript - Phonegap Cordova Statusbar 插件创建双条

ios - 带有 FCM token 的设备的 Firebase 通知显示已发送但未收到

cocoa-touch - 在 iOS 上解析 64 位无符号整数

c - 如何在不循环打印 "error"消息的情况下运行它

Windows 批处理 For 循环在一台服务器上不工作,在其他服务器上工作