在 Gamescene 中显示 UIAlertViewController?
Display UIAlertViewController in Gamescene?
显然 GameScene 不能 .presentViewController,所以这就是我所做的。
let msg="Congrats... You died!\n"+"Score: "+String(score)
let myAlert: UIAlertController = UIAlertController(title: msg, message: "Try Again?", preferredStyle: .Alert)
let okAction = UIAlertAction(title: "Play Again", style: UIAlertActionStyle.Default) {
UIAlertAction in
self.timer.invalidate() //timer is not properly invalidating... it multple bacteria spawn... eevery 10 seconds with t difference ~0.5 seconds <-- FIXED as of 2/29/16
self.timer=NSTimer.scheduledTimerWithTimeInterval(10, target: self, selector: Selector("spawnBacteria"), userInfo: nil, repeats: true)
self.spawnBacteria()
score=0
// print("FIRE")
}
myAlert.addAction(okAction)
// _______________
self.view?.window?.rootViewController?.presentViewController(myAlert, animated: true, completion: nil)
但是,这似乎不适用于多个视图,我想为我的游戏菜单添加另一个视图。那么,如何创建这个 UIAlertViewController 并将其添加到 GameScene 中呢?任何帮助深表感谢。
注意:我知道有人问了一个相同的问题,但我不明白答案,而且我不知道将答案中提供的代码放在哪里,所以请不要忽略这个问题。谢谢
您可以使用 JSAlertView,根据 运行 iOS 版本使用 old/new API 显示警报。这会在 window 上显示警报,因此您无需担心 view/navigation 层次结构。
希望这会有所帮助。
显然 GameScene 不能 .presentViewController,所以这就是我所做的。
let msg="Congrats... You died!\n"+"Score: "+String(score)
let myAlert: UIAlertController = UIAlertController(title: msg, message: "Try Again?", preferredStyle: .Alert)
let okAction = UIAlertAction(title: "Play Again", style: UIAlertActionStyle.Default) {
UIAlertAction in
self.timer.invalidate() //timer is not properly invalidating... it multple bacteria spawn... eevery 10 seconds with t difference ~0.5 seconds <-- FIXED as of 2/29/16
self.timer=NSTimer.scheduledTimerWithTimeInterval(10, target: self, selector: Selector("spawnBacteria"), userInfo: nil, repeats: true)
self.spawnBacteria()
score=0
// print("FIRE")
}
myAlert.addAction(okAction)
// _______________
self.view?.window?.rootViewController?.presentViewController(myAlert, animated: true, completion: nil)
但是,这似乎不适用于多个视图,我想为我的游戏菜单添加另一个视图。那么,如何创建这个 UIAlertViewController 并将其添加到 GameScene 中呢?任何帮助深表感谢。 注意:我知道有人问了一个相同的问题,但我不明白答案,而且我不知道将答案中提供的代码放在哪里,所以请不要忽略这个问题。谢谢
您可以使用 JSAlertView,根据 运行 iOS 版本使用 old/new API 显示警报。这会在 window 上显示警报,因此您无需担心 view/navigation 层次结构。
希望这会有所帮助。