iOS:从后台线程创建 UIImage? [英] iOS: Create UIImage from the background thread?

查看:55
本文介绍了iOS:从后台线程创建 UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple 文档说:

因为图像对象是不可变的,所以创建后不能更改它们的属性.大多数图像属性是使用随附图像文件或图像数据中的元数据自动设置的.图像对象的不可变特性也意味着它们可以安全地从任何线程创建和使用.

Because image objects are immutable, you cannot change their properties after creation. Most image properties are set automatically using metadata in the accompanying image file or image data. The immutable nature of image objects also means that they are safe to create and use from any thread.

链接

此外,如果您查看此UIImage 的线程安全性" 问题的答案,结论是从任何线程使用它们都是安全的(至少从 iOS 9 开始).

Also if you look at the answers of this "Thread safety of UIImage" question, it is concluded that it is safe to use them from any thread (at least since iOS 9).

然而,有些评论抱怨问题,尤其是关于在后台线程上创建 UIImages 的问题.

Yet, there are comments that complain about issues, especially about creating UIImages on a background thread.

就我而言,我确信这会导致动画停止工作的问题.有人对此有见解吗?

In my case I'm sure that this leads an issue where animations stop working. Does anybody have insights on this?

推荐答案

我看不到您的代码,但如果您遇到动画问题,我怀疑这是 UIImage 与 UIImageView 的问题.

I can't see your code but I suspect this is a UIImage vs UIImageView issue if you're experiencing animation problems.

A UIImage 管理 屏幕外图像数据.
UIImageView 显示你的图像到您的用户界面.

A UIImage manages image data off screen.
A UIImageView displays your image on to your user interface.

使用 UIImage 从主线程处理图像数据很好.
使用 UIImageView 显示或动画图像不是.

Handling image data off the main thread with UIImage is fine.
Displaying or animating an image with UIImageView is not.

这篇关于iOS:从后台线程创建 UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆