Ios 无法更改SKView背景色

Ios 无法更改SKView背景色,ios,swift,cocoa-touch,sprite-kit,Ios,Swift,Cocoa Touch,Sprite Kit,这是iOS9。我无法设置SKView的背景色,它总是以默认的灰色渲染。有办法解决这个问题吗 let frame = CGRect(x: 0, y: 0, width: 200, height: 100) let spriteView = SKView(frame: frame) spriteView.backgroundColor = .blueColor() self.view.addSubview(spriteView) 运行上述代码时,SKView为灰色而不是蓝色。我真正想做的是设置al

这是iOS9。我无法设置SKView的背景色,它总是以默认的灰色渲染。有办法解决这个问题吗

let frame = CGRect(x: 0, y: 0, width: 200, height: 100)
let spriteView = SKView(frame: frame)
spriteView.backgroundColor = .blueColor()
self.view.addSubview(spriteView)
运行上述代码时,SKView为灰色而不是蓝色。我真正想做的是设置
allowsttransparency=true
,但如果我不能将背景色更改为
clearColor
,我就无法实现这一点

还有人碰到这个吗?有解决办法吗

更新

即使有@Danilo的建议,它仍然显示为灰色:

let frame = CGRect(x: 0, y: 0, width: 200, height: 100)
let spriteView = SKView(frame: frame)
spriteView.backgroundColor = .clearColor()
spriteView.allowsTransparency = true
spriteView.opaque = false
更新


显然,设置SKView的
backgroundColor
没有效果,但是如果您将其设置为任何值,那么
allowtransparency=true
就不起作用了。

除了添加
SKView
,我们还需要一个
SKView
呈现的
SKScene
;然后我们调整/更改
SKScene
backgroundColor
。场景将依次添加一个节点

例如:

//create a SKView, which takes up the same frame as our view
let spriteView = SKView(frame: self.view.bounds)

//adding spriteView as a child view of our view
self.view.addSubview(spriteView)

//Here, we create a scene, which is the root object of
//the graph
let scene = SKScene(size: spriteView.frame.size)
scene.backgroundColor = .orangeColor()

//As said, we present the scene with our SKView
spriteView.presentScene(scene)

//Here, we create a node, which will be added by our scene
//This node takes up a size that you originally created and has the 
//background color set to blue
let nodeFrame = CGRect(x: 0, y: 0, width: 200, height: 100)
let node = SKSpriteNode(color: .blueColor(), size: nodeFrame.size)

//The following just serves to show how we can adjust the node's   
//position; I will leave that to you
node.position = CGPointMake(scene.frame.size.width - 200, scene.frame.size.height - 100)

//Finally, we add the node to our scene
scene.addChild(node)

尝试设置不透明=NO@Danilo仍然是灰色:(谢谢!这不是很好的答案,但它帮助我找到了它。显然,设置SKView的
backgroundColor
没有效果,但是如果您尝试将其设置为任何值,那么
allowtransparency=true
就不起作用了。
    let spriteView = SKView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
    let spriteKitScene = SKScene(size: spriteView.frame.size)
    spriteKitScene.backgroundColor = SKColor.blackColor()
    spriteView.presentScene(spriteKitScene)
    self.view.addSubview(spriteView)