【问题标题】:Immediately initialize UIImage立即初始化 UIImage
【发布时间】:2012-03-13 02:11:19
【问题描述】:

我有一个 UIImage 对象数组,如下所示:

frames = [[NSMutableArray alloc] initWithCapacity:[sortedArray count]];
for (int nDx = 0; nDx < [sortedArray count]; nDx++)
{
    NSString * sImageName = [sortedArray objectAtIndex:nDx];
    [frames addObject:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", imageFolderPath, sImageName]]];
}

在我的计时器方法中,我正在执行以下操作以循环显示图像:

self.image = [frames objectAtIndex:currentFrame];
currentFrame++;
if (currentFrame >= [frames count]) currentFrame = 0;

但是,当我启动计时器时,图像第一次循环变慢,然后一切都按预期工作。我也试过没有计时器。

如何预加载图像,以便在我的计时器启动时可以使用它们?

感谢您的帮助。

【问题讨论】:

    标签: objective-c xcode ios5 uiimage


    【解决方案1】:

    您可以使用this 代码使用单独的线程来加载图像。

    如果可行,我会在此处添加。

    【讨论】:

      【解决方案2】:

      这里的img_array是UIImageView

       img_array.animationImages = [NSArray arrayWithObjects:
                                         [UIImage imageNamed:@"img_1.png"],
                                         [UIImage imageNamed:@"img_2.png"],
                                         [UIImage imageNamed:@"img_3.png"],nil];
      
      
       [img_array.animationImages setAnimationRepeatCount:HUGE_VAL];
       img_array.animationImages .animationDuration = 4;
       [img_array.animationImages startAnimating]; 
       [self.view addSubview:img_array]
      

      试试这个:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-12
        • 1970-01-01
        • 1970-01-01
        • 2019-07-16
        • 2012-01-16
        • 2012-05-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多