ios - Swift - 将 SKScene 叠加到 UIView 上 - 灰色背景

标签 ios swift uiview sprite-kit

我是 Swift 和 Xcode 的新手,只是在玩弄 SpriteKit。我所做的是在 main.storyboard 中创建了一个 UIViewUIView(名为 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 :

enter image description here

它默认是一个SKView:

enter image description here

将它的类更改为 UIView 就可以了。顺便说一句,在 SKView 上设置 backgroundColor 没有任何效果。

关于ios - Swift - 将 SKScene 叠加到 UIView 上 - 灰色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45023829/

相关文章:

ios - 在自定义 UIView 中设置 IBOutlet 标签的文本

ios - 在 Swift 中的 UITextView 上放置阴影

ios - swift OutputStream 找不到成员 "write"

ios - iPhone 5s Touch ID 传感器 API

ios - "Use of unresolved indentifier ' 自身 '"带按钮.addTarget

ios - super.viewDidLoad()前后不同的UIImageView.frame.size : what am I doing wrong?

ios - UIActivityViewController 中的 MFMailComposeViewController 具有默认的蓝色色调

ios - 如何使用 Photos Framework 在 iOS 9 中获取图像元数据

ios - 如何将数组保存到 CoreData?

ios - UIButton 将文本设置在图像顶部