我有一个基本的SpriteKit游戏。
我基本上想做的是使用函数create_new_ui()
创建一个UIView
并将其隐藏在幕后。
override func viewDidLoad()
{
super.viewDidLoad()
create_new_ui()
if let view = self.view as! SKView?
{
// Load the SKScene from 'GameScene.sks'
let scene = MainScene()
// Set the scale mode to scale to fit the window
scene.scaleMode = .resizeFill
scene.anchorPoint = CGPoint(x: 0.5, y: 0.5)
// Present the scene
view.presentScene(scene)
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
}
}
func create_new_ui()
{
let ui_view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
ui_view.center = CGPoint(x: self.view.frame.size.width / 2, y: self.view.frame.size.height / 2)
ui_view.backgroundColor = UIColor.red
self.view.addSubview(ui_view)
}
您能告诉我如何将ui_view
移到SKScene
后面吗?
我尝试了sendSubviewToBack(_:)
,但没有任何效果。有什么想法吗?
答案 0 :(得分:0)
有几种方法可以做到这一点。一种方法是在视图出现后将其直接添加到窗口中。
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
addFakeView()
}
func addFakeView(){
let fview = UIView.init(frame: CGRect.init(x: 100, y: 400, width: 100, height: 100))
fview.backgroundColor = UIColor.green
view.window?.insertSubview(fview, at: 0)
}