立即初始化UIImage

时间:2012-03-13 02:11:20

标签: objective-c xcode ios5 uiimage

我有一个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;

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

如何预先加载图像,以便在我的计时器启动时准备就绪?

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

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

如果有效,我会在这里添加。

答案 1 :(得分:0)

这里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]

试试这个:

相关问题