我正在尝试使用以下按钮显示UIAlterController(一旦设置了场景):
我的代码如下所示(我将警报控制器置于一个动作中,因此它首先显示场景,0.5秒后它应该开始显示警报):
//make action
var actionBlock = SKAction.runBlock({
//alert controller
var alert = UIAlertController(title: "Welcome", message: "Are you sure you want to proceed?", preferredStyle: UIAlertControllerStyle.Alert)
//action with no handler
var acceptAction = UIAlertAction(title: "Yes", style: UIAlertActionStyle.Cancel, handler: nil)
//action thats supposed to transition to MenuScene (AFTER BEING TAPPED!!)
var leaveAction = UIAlertAction(title: "Back to Menu", style: UIAlertActionStyle.Destructive, handler: {_ in self.backToMenu()})
//add action to the alert controller
alert.addAction(acceptAction)
alert.addAction(leaveAction)
//add alert controller to view
self.view?.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil)
}
//wait for 0.5s action
var wait = SKAction.waitForDuration(0.5)
//run the action
self.runAction(SKAction.sequence([wait, actionBlock]))
我把它放在了DidMoveToView函数中。当我运行代码时,它立即转换回MenuScene,甚至没有等待用户点击其中一个动作,然后警报仍然在屏幕上(但在MenuScene上)。 我真的很困惑,我已经在这几个小时了,但我无法弄清楚我的错误是什么,以及如何让它发挥作用.. 有人帮忙吗?任何有效的代码都会非常感激!!!