uiimage 完整 iphone

发布于 2024-08-25 11:11:03 字数 97 浏览 3 评论 0原文

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

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

执行此操作的一般最佳实践是什么?

Is there such a thing as an "on load complete" for images in iphone?

I want to be able to destroy a UIActivity indicator once and image is loaded.

What the general best practice for doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃不饱 2024-09-01 11:11:03

如果您只是想在 UIImage 加载并在 UIImageView 中正确显示后关闭 UIActivityIndi​​catorView,您可以尝试以下操作:

- (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];
}

我有承认,我没有测试上面的代码。如果有效请留下评论。

If you simply want to dismiss a UIActivityIndicatorView after a UIImage has been loaded and displayed properly in a UIImageView, you can try the following:

- (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];
}

I have to admit, I did not test the above code. Please leave a comment if it works.

夏天碎花小短裙 2024-09-01 11:11:03

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

如果您想在加载图像时执行其他操作,则必须在后台线程上加载图像,这可以使用 Core Graphics C API 来实现。 UIImage 不是线程安全的,只能在主线程上使用。

UIImage has a synchronous API. This means that when you create (or draw) a UIImage, it has been loaded and decompressed. This also means that a method call to creating (or drawing) a UIImage can block for as long as it takes to load that image.

If you want to do other things while loading an image, you have to load the image on a background thread, which is possible using the Core Graphics C API. UIImage is not thread safe and can be used on the main thread only.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文