【发布时间】:2019-03-21 01:35:59
【问题描述】:
我有一个基本的 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(_:),但没有效果。有什么想法吗?
【问题讨论】:
-
添加新视图后尝试在 SKScene 上使用 bringSubviewToFront(_:)
-
试过了。没有任何影响。
-
你到底尝试了什么?
-
bringSubviewToFront(_:),返回,改变 layer.zPosition。如果我理解正确,视图只有一个我创建的子视图(ui_view)。场景不是子视图。
-
是的,但是您在代码中的哪个位置尝试了这些?
标签: ios swift sprite-kit