如何将子画面添加到ViewController?

时间:2019-01-22 07:56:33

标签: swift xcode sprite-kit

我已经将Viewcontroller制作为SKview,以便可以添加内容。

getContactInfo(state: BillingState): ContactUsInfo {
  return state.contactUsInfo;
}

let skview: SKView = { let view = SKView() view.translatesAutoresizingMaskIntoConstraints = false return view }() self.view.addSubview(skview) skview.topAnchor.constraint(equalTo: view.topAnchor).isActive = true skview.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true skview.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true skview.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true 不起作用。

1 个答案:

答案 0 :(得分:1)

您无法将精灵添加到视图控制器。您不能将精灵添加到SKView中。您必须首先创建一个SKScene并显示它:

let scene = SKScene(size: skview.bounds.size)
skview.presentScene(scene)

然后您可以将精灵添加到场景中

scene.addChild(player)