【问题标题】:Add a share button - Swift添加分享按钮 - Swift
【发布时间】:2018-07-05 17:32:31
【问题描述】:

如何将分享按钮编码到我的 SpriteKit 场景中?我已经看过有关如何制作它的教程,但是这是在 Main.storyboard 和 ViewController.swift 中,我在 MenuScene.swift(Cocoa Touch 类)中对其进行编码并在 MenuScene.sks(SpriteKit 场景)中显示它。我正在使用 Swift 4 和最新版本的 Xcode (9.4.1),我的应用程序适用于 iOS 9 及更高版本。

提前致谢!

【问题讨论】:

    标签: ios swift xcode sprite-kit uiactivityviewcontroller


    【解决方案1】:

    此代码将打开一个活动视图,并让您与它分享您想要的任何内容。

    if var top = scene?.view?.window?.rootViewController {
        while let presentedViewController = top.presentedViewController {
            top = presentedViewController
        }
        let activityVC = UIActivityViewController(activityItems: ["This is an array of items that will be shared. Including Images, Numbers, and text (like this)"], applicationActivities: nil)
        activityVC.popoverPresentationController?.sourceView = view
        top.present(activityVC, animated: true, completion: nil)
    }
    

    当然,它需要在touchesBegan 方法或函数中调用。要分享某些内容,您需要将其放入 activityVC 中的数组中。

    这不是分享按钮,这只是用于将某些内容分享给另一个应用程序的代码。您需要将其放入函数或 touchesBegan 中,并在您想要共享某些内容时单独调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多