在SLComposeServiceViewController中

在SLComposeServiceViewController中

本文介绍了在SLComposeServiceViewController中更改预览图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Safari共享扩展程序,可以从当前URL获取特定图像.这部分已经完成,但是现在我尝试用我从URL抓取的图像替换SLComposeServiceViewController上的预览图像.我似乎找不到改变SLComposeServiceViewController自动生成的预览图像的方法

I have created a Safari Share Extension where I get a specific image from the current URL. That part is done but now I am trying to replace the preview image on the SLComposeServiceViewController with the one I scraped from the URL. I cannot seem to find a way to change the preview image that is automatically generated by SLComposeServiceViewController

如何更改此图像?

我尝试查找NSExtenstionContextinputItems属性,但只能在其中看到URL.

I've tried looking for at the inputItems property of NSExtenstionContext but only can see the URL in there.

extension NSExtensionContext {
  for item in self.inputItems {
    if let extenstionItem = item as? NSExtensionItem {
      print("attachments = \(extenstionItem.attachments)")
    }
  }
}

attachments = Optional([<NSItemProvider: 0x12d513e70> {types = ( "public.url")}])

attachments = Optional([<NSItemProvider: 0x12d513e70> {types = ( "public.url")}])

我希望可以更改此图像而不必创建自己的视图,因为这是我需要对默认设置进行的唯一更改.

I'm hoping that I can change this image without having to create my own view since this is the only change I need to make to the default.

即使能够默认隐藏放置在其中的图像也会很有帮助!

Even being able to hide the image placed there by default would be helpful!

推荐答案

我找到了实现此目的的方法.您可以在SLComposeServiceViewController子类中重写loadPreviewView(),并返回带有图像的UIImageView(或任何视图).要在同一运行时期间对其进行更新,请在类中保留对其的引用.

I found the way to accomplish this. You override loadPreviewView() in the SLComposeServiceViewController subclass and return the UIImageView (or any view) with the image. To update it during the same runtime, you keep a reference to it in the class.

override func loadPreviewView() -> UIView! {
  imagePreviewView = UIImageView(image: UIImage(named: "imageName"))
  return imagePreviewView
}

这篇关于在SLComposeServiceViewController中更改预览图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 14:16