【发布时间】:2017-08-20 06:21:45
【问题描述】:
我在 Xcode 中使用 sprite kit 和场景开发了一个游戏。现在我正在尝试集成将高分发布到 twitter 和 Facebook 的功能。我环顾四周,大多数人说使用 SLComposeServiceViewController 很好,直到我尝试展示它。因为我的应用程序真的只使用场景,所以它们从来没有成员函数“presentViewController(....)”。因此,我永远无法呈现它。有谁知道解决这个问题的方法吗?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch:UITouch = touches.first!
let touchLocation = touch.location(in: self)
let touchedNode = self.atPoint(touchLocation)
if (touchedNode.name == "tryAgain") {
let nextScene = Scene_LiveGame(size: self.scene!.size)
nextScene.scaleMode = self.scaleMode
self.view?.presentScene(nextScene, transition: SKTransition.fade(withDuration: 0.5))
}
else if (touchedNode.name == "share") {
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook) {
let fShare = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
self.presentViewController(fShare!, animated: true, completion: nil)
//^This is where my problem is. Xcode is telling me that self has no member function presentViewController which I totally understand, because its a scene and thus doesn't share those functions. But every resource online has shown me this is the only way to do it
}
}
【问题讨论】:
-
请发布您正在使用的代码(相关部分)。但一般来说,您可以在适当的视图控制器中指定视图控制器相关的方法,并在您想要调用这些方法时从场景中发布通知。
-
else if块中的代码应替换为可以发布通知的代码。此外,它应该被移动到一个适当的视图控制器,该控制器具有必需的成员方法并侦听所提到的通知。 -
我不确定我是否遵循,我将代码移动到我制作的自定义视图控制器类中,但是我仍然无法从我的场景中调用它。
-
您所说的视图控制器应该监听从场景发布的通知。如果您仍然卡住,请告诉我,等我回家后,我会为您写一个示例。
-
我还是很卡。任何帮助都会很棒
标签: ios swift facebook twitter