我是 Swift 和 Xcode 的新手,只是在玩弄 SpriteKit。我所做的是在 main.storyboard 中创建了一个 UIView
。 UIView
(名为 overlayedGameScene
)只占据了大约一半的屏幕,所以你应该
能够看到主要的 UIView
(self.view
)。
import UIKit
import SpriteKit
import GameplayKit
class GameViewController: UIViewController {
@IBOutlet var overlayedGameScene: SKView!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.blue
self.view.alpha = 1
if let theView = overlayedGameScene as SKView? {
if let theScene = SKScene(fileNamed: "GameScene.sks") {
theScene.scaleMode = .aspectFill
theView.presentScene(theScene)
}
}
}
}
它运行良好,但唯一的问题是当我在模拟器中运行它时,当我在 Storyboard 和编程中将其更改为蓝色时,主视图是灰色的。我还在 Storyboard中和以编程方式更改了 alpha。
这是它在模拟器中的样子。
我应该在主视图上添加另一个蓝色的 UIView
吗?发生这种情况是否有原因。
最佳答案
注意你的GameViewController
的 View :
它默认是一个SKView
:
将它的类更改为 UIView
就可以了。顺便说一句,在 SKView
上设置 backgroundColor
没有任何效果。
关于ios - Swift - 将 SKScene 叠加到 UIView 上 - 灰色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45023829/