[英]UIActivityItemSource render image in background
My app takes about 10 seconds to render a full-resolution image with many filters applied. 我的应用大约需要10秒钟才能渲染出应用了许多滤镜的全分辨率图像。 I want to allow the user to save it or share it using
UIActivityViewController
. 我想允许用户保存或使用
UIActivityViewController
共享它。 I've subclassed UIActivityItemSource
so it provides a thumbnail when the activity view opens. 我将
UIActivityItemSource
子类化,因此在活动视图打开时它会提供缩略图。
How can I make it so my item source renders the image in the background? 我该如何做才能使我的物品来源在后台渲染图像? Specifically, I would like to allow the view controller to minimize and display a progress bar.
具体来说,我想允许视图控制器最小化并显示进度条。
I already have the progress bar working, I just need to know how to do the following in the background: 我已经有进度条在工作,我只需要知道如何在后台执行以下操作:
func activityViewController(activityViewController: UIActivityViewController, itemForActivityType activityType: String) -> AnyObject? {
// this step takes 10 seconds
// is there any way to do it in the background?
// So: the activity view can minimize
// and the main thread is free to update my progress bar
let image = renderFullImage()
return image
}
The trick was to use a UIActivityItemProvider
instead of UIActivityItemSource
. 诀窍是使用
UIActivityItemProvider
代替UIActivityItemSource
。 You are supposed to override the item
method, which is already called in the background. 您应该覆盖
item
方法,该方法已经在后台调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.