添加分享按钮 - Swift

Add a share button - Swift

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

提前致谢!

此代码将调出一个 activity 视图,您可以通过它分享您想要的任何内容。

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 中,并在您想共享某些内容时单独调用它。