带有自定义View Controller的iOS共享扩展 [英] iOS Share Extension with custom View Controller

查看:175
本文介绍了带有自定义View Controller的iOS共享扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个共享扩展程序,以允许将Youtube视频共享到我的应用中,并且很难顺利地呈现我的自定义UI.我想要代替只包含原始Youtube URL的默认视图控制器,而是要做类似于Facebook扩展的视觉效果,显示缩略图和视频标题. 我的第一次尝试是编辑MainInterface故事板ShareViewController,但这样做简短地显示了我的自定义界面,然后默认UI布局将其覆盖".所以我最终将另一个带有UI的视图控制器添加到情节提要中,并在添加的ShareViewController中

I'm creating a Share Extension to allow to share Youtube videos into my app and am having a hard time to present my custom UI smoothly. Instead of the default view controller which just contains the raw Youtube URL, I want to do something visually similar to Facebook's extension, displaying a thumbnail and the video title. My first attempt at it was editing the MainInterface storyboard ShareViewController, but doing so briefly shows my custom interface and thet get's "overriden" by the default UI layout. So I ended up adding another view controller with my UI to the storyboard and in the ShareViewController I added

override func presentationAnimationDidFinish() {
    super.presentationAnimationDidFinish()
    DispatchQueue.main.async {
        self.pushConfigurationViewController(customVC)
    }

明显的问题是,在推送自定义按钮之前,我仍然可以看到默认的View Controller. 所以问题是,当共享扩展名启动时,如何立即显示我的自定义UI?我已经尝试了.plist中的 NSExtensionPrincipalClass ,但是没有任何积极的结果

The problem with this obviously is that I still get to see the default View Controller before my custom one is pushed. So the question would be how do I get to show my custom UI right away when the share extension is started? I've experimented with the NSExtensionPrincipalClass in the .plist but did not have any positive results

预先感谢

推荐答案

好吧,进一步挖掘和搜索我发现我必须将 ShareViewController 设置为 UIViewController ,而不是** SLComposeServiceViewController **.当我在情节提要板上设计界面时,我保持了.plist的原样,但必须考虑到VC进入全屏显示的问题,如下所述:

Well, digging and searching a bit more I found out that I had to make my ShareViewController a subclass of UIViewController instead of ** SLComposeServiceViewController**. As I designed my interface on storyboard, I left the .plist as it was, but had to take into account the problem of VC going full screen described here: iOS 8 Share Extension custom view controller size

我在这里用@Dale答案来解决它.

I took @Dale answer there for solving it.

这篇关于带有自定义View Controller的iOS共享扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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