我正在尝试弄清楚如何为我的 SpriteKit 游戏使用共享表,当我尝试从我的场景中呈现 View Controller 时,它给我一个错误。
if self.nodeAtPoint(location) == self.shareButton {
var tempMessage = "I just got \(score) on [insert app]"
let activityVC:UIActivityViewController = UIActivityViewController(activityItems: [tempMessage], applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
}
这是在我的 GameOverScene 中。你究竟是如何在 Swift 中管理 View Controller 的,因为我看到的答案是在 OBJ-C 中。
谢谢!
最佳答案
好吧,我做了一些挖掘并找到了一个可行的解决方案。
基本上,我使用 NSNoticationCenter 并在我的 GameViewController 文件中设置 View Controller 。
override func viewDidLoad() {
.
.
NSNotificationCenter.defaultCenter().addObserver(self, selector: "showSocialNetworks", name: "showSocialNetworksID", object: nil)
}
并使函数被调用
func showSocialNetworks(){
var tempMessage = "Insert your message to be shared on social network"
let activityVC:UIActivityViewController = UIActivityViewController(activityItems: [tempMessage], applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
}
现在跳回我的 GameOverScene,我将其设置为当用户点击分享按钮时,它会执行以下代码
if self.nodeAtPoint(location) == self.shareButton {
NSNotificationCenter.defaultCenter().postNotificationName("showSocialNetworksID", object: nil)
}
这可能不是最简洁的方法,但对我有用。希望这对您有所帮助!
关于swift - 如何在 SKScene 中呈现 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28378580/