adding uitextfield or (textentry box with keyboard

2019-07-29 10:17发布

问题:

I am recently working on sprite kit to create a simple game where user input name as identity and moves forward to play game and has option to edit name or replace name. Which is best option to use uitextfield: in skscene or viewcontroller? Or any other solutions?

I had tried with uitextfield adding in skscene but got memory issue (since i called scene from viewwilllayoutSubview

   override func viewWillLayoutSubviews() {
    let skView = self.view as! SKView
    skView.ignoresSiblingOrder = true
    let scene =
        NameEntryScene(size:CGSize(width: 1024, height: 718))
    scene.scaleMode = .aspectFill
    skView.presentScene(scene)

}

which I followed stackoverflow others answer to add uitextfield in gamesence at didMove(to view: SKView).

Also created uitextfield in viewcontroller and pass its instance all over the gamesence with action of isHidden true and false to remove memory issue, which worked but I can't work like this if i have many uitextfield's at various postions.

Any suggestion and help is very much appreciated. Thanks in advance.