如何将共享按钮编码到我的 SpriteKit 场景中?我看过关于如何制作它的教程,但是这是在 Main.storyboard 和 ViewController.swift 中,我在我的 MenuScene.swift(Cocoa Touch 类)中对其进行编码并在 MenuScene.sks(SpriteKit 场景)中显示它。我正在使用 Swift 4 和最新版本的 Xcode (9.4.1),我的应用程序适用于 iOS 9 及更高版本。
提前致谢!
最佳答案
此代码将调出一个事件 View ,并让您与它分享您想要的任何内容。
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
中,并在您想要共享某些内容时单独调用它。
关于ios - 添加分享按钮 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51197034/