When programatically creating a ViewController, how can I set its view to be of type SKVIew?

前端 未结 1 1391
孤街浪徒
孤街浪徒 2021-01-21 12:07

I am developing a game in iOS on XCode. I have several SKScenes each associated with a UIViewController class. So in each of the view controller\'s viewDidLoad, I create

<
1条回答
  •  走了就别回头了
    2021-01-21 12:44

    Try implementing the loadView method on your custom ViewController, like so:

    override func loadView() {
            self.view = SKView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
    }
    

    This is what Apple's documentation states:

    This is where subclasses should create their custom view hierarchy if they aren't using a nib. Should never be called directly.

    0 讨论(0)
提交回复
热议问题