Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在iOS上预加载图像_Objective C_Ios_Uiimage - Fatal编程技术网

Objective c 在iOS上预加载图像

Objective c 在iOS上预加载图像,objective-c,ios,uiimage,Objective C,Ios,Uiimage,我使用泛洪代码预加载图像: NSMutableArray *test_loose_preload = [[NSMutableArray alloc] initWithCapacity:test_loose_array.count]; for (int aniCount = 0; aniCount < test_loose_array.count; aniCount++) { UIImage *frameImage = [test_loose_array objectAtInde

我使用泛洪代码预加载图像:

NSMutableArray *test_loose_preload = [[NSMutableArray alloc] initWithCapacity:test_loose_array.count];

for (int aniCount = 0; aniCount < test_loose_array.count; aniCount++) {

    UIImage *frameImage = [test_loose_array objectAtIndex:aniCount];
    UIGraphicsBeginImageContext(frameImage.size);
    CGRect rect = CGRectMake(0, 0, frameImage.size.width, frameImage.size.height);
    [frameImage drawInRect:rect];
    UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    [test_loose_preload addObject:renderedImage];

}

test_loose = test_loose_preload;
NSMutableArray*test_loose_preload=[[NSMutableArray alloc]initWithCapacity:test_loose_array.count];
for(int-aniCount=0;aniCount
是否有可能在该块内检查图像是否已预加载,并且不再需要预加载该图像

谢谢你的建议

主题外:

您可以对每个
循环使用

for (UIImage *frameImage in test_loose_array) {

  UIGraphicsBeginImageContext(frameImage.size);
  ...
  [test_loose_preload addObject:renderedImage];
}

也许我误解了这个问题,但在我看来,如果您已经构建了一个图像并将其填充到您的test\u loose\u预加载数组中,那么该图像是“预加载”的。我推测您可能担心其他线程可能会在完成数组之前执行相同的工作


如果是这样,那么您可以通过检查[test_loose_preload objectAtIndex:aniCount]来检查这一点,如果结果为非零,则跳过该结果并转到下一个索引。

我不知道它是否完全符合您的要求,但WWDC 2012视频“构建、归档和提交您的应用程序”详细介绍了如何加载图像以最大限度地减少用户的等待时间:你的意思是不是这样?对于(int aniCount=0;aniCount