我需要帮助在游戏场景中呈现警报视图。由于GameScene.Swift不是标准的ViewController,因此我目前很难做到这一点。如果有帮助的话,我需要这样做是因为我需要用户输入一个值,该值用作我的游戏中球形Sprite Kit节点的坐标。输入只是一个标准整数,所以这不是问题。欢迎任何其他想法,可以不通过警报视图来实现。
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
let view = self.view as! SKView
if view.scene == nil {
view.showsFPS = false
view.showsNodeCount = false
let gameScene = GameScene(size: view.bounds.size)
gameScene.scaleMode = SKSceneScaleMode.AspectFill
view.presentScene(gameScene)
}
}
这在GameViewController文件中
var vc : GameViewController!
override init(size: CGSize) {
super.init(size: size)
let alertController = UIAlertController(title: "Bll Starting Position", message: "Please Enter a X Coordinate Value IN Range 0 to 345 ", preferredStyle: .Alert)
alertController.addTextFieldWithConfigurationHandler { (textField) in
textField.placeholder = "Value Must Be In Range 0 To 345"
textField.autocapitalizationType = UITextAutocapitalizationType.None
textField.autocorrectionType = UITextAutocorrectionType.No
textField.clearsOnBeginEditing = true
textField.clearsOnInsertion = true
textField.clearButtonMode = UITextFieldViewMode.Always
let cancelBtn = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
let confirmBtn = UIAlertAction(title: "Confirm", style: .Default, handler: { (confirmView) in
if let field = alertController.textFields![0] as? UITextField {
}
})
alertController.addAction(confirmBtn)
alertController.addAction(cancelBtn)
self.vc.presentViewController(alertController, animated: true, completion: nil)
}
谢谢