gpt4 book ai didi

ios - 在 GameViewController 中的 SKScene 后面显示 UIView

转载 作者:行者123 更新时间:2023-11-29 05:54:54 24 4
gpt4 key购买 nike

我有一个基本的 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(_:)但没有效果。有什么想法吗?

enter image description here

最佳答案

有几种方法可以做到这一点。一种方法是在 View 出现后直接将其添加到窗口。:

   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)
}

关于ios - 在 GameViewController 中的 SKScene 后面显示 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55257345/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com