1

iphone中的图像是否有“加载完成”之类的东西?

我希望能够销毁一次 UIActivity 指示器并加载图像。

这样做的一般最佳做法是什么?

4

2 回答 2

0

UIImage有一个同步 API。这意味着当您创建(或绘制) aUIImage时,它已被加载并解压缩。这也意味着创建(或绘制)a 的方法调用UIImage可以阻塞,只要它需要加载该图像。

如果你想在加载图像时做其他事情,你必须在后台线程上加载图像,这可以使用 Core Graphics C API。UIImage不是线程安全的,只能在主线程上使用。

于 2010-03-16T09:24:01.990 回答
0

如果您只是想UIActivityIndicatorView在 aUIImage已加载并在 a 中正确显示后关闭 a UIImageView,您可以尝试以下操作:

- (void)loadImageAtPath:(NSString*)path
{
    // show the indicator
    [_myIndicatorView startAnimating];

    // give UIKit a chance to setup and draw the view hierarchy:
    [self performSelector:@selector(_loadImageAtPath:)
               withObject:path
               afterDelay:0];
}

- (void)_loadImageAtPath:(NSString*)path
{
    // load the image
    _myImageView.image = [UIImage imageWithContentsOfFile:path];

    // force the image to load and decompress now
    _myImageView.image.CGImage

    // image is ready, so we can remove the indicator view
    [_myIndicatorView removeFromSuperview];
}

我不得不承认,我没有测试上面的代码。如果有效,请发表评论。

于 2010-03-16T10:06:37.987 回答