【发布时间】:2016-02-25 15:53:46
【问题描述】:
我有一个 GameOver 类,它显示背景颜色和 playAgain 按钮。 添加“view.addSubview(self.playAgainButton)”后,背景色弹出,突然从屏幕上消失。 playAgain-Button 仍然存在。
如果我删除 addSubview 调用,背景颜色会保留在那里。
谁能帮帮我?
class GameOver: SKScene{
var playAgainButton = UIButton()
var playAgainButtonImage = UIImage(named: "PlayAgainButton")
override func didMoveToView(view: SKView) {
backgroundColor = UIColor.redColor()
self.playAgainButton = UIButton(type: UIButtonType.Custom)
self.playAgainButton = setImage(playAgainButtonImage, forState: .Normal)
self.playAgainButton.frame = CGRectMake(self.frame.size.width / 2, self.frame.size.height / 2, 190, 70)
self.playAgainButton.layer.anchorPoint = CGPointMake(1.0, 1.0)
self.playAgainButton.layer.zPosition = 0
// If I add this line -> backgroundcolor disappears
view.addSubview(self.playAgainButton)
}
}
我的 GameScene gameOver 函数是这样的(可能有错误?)
func gameOver() {
let skView = self.view! as SKView
skView.ignoresSiblingOrder = true
self.scene?.removeFromParent()
let transition = SKTransition.fadeWithColor(UIColor.grayColor(), duration: 1.0)
transition.pausesOutgoingScene = false
var scene: GameOver!
scene = GameOver(size: skView.bounds.size)
scene.scaleMode = .AspectFill
skView.presentScene(scene, transition: transition)
}
【问题讨论】:
-
您的意思是在您正在移动到的视图或您当前所在的视图(离开)上设置背景颜色?
-
看起来他是在场景上设置背景,然后在视图顶部扔了一个按钮,你确定场景本身没有消失,而不仅仅是背景颜色?跨度>
-
@Putz1103:我要移动到的视图的背景颜色消失了
-
@Knight0fDragon 视图不是场景的一部分吗?按钮如何可见但背景色不可见。你能给我一些建议如何解决这个问题吗?
-
我自己发现了这个问题。我必须将子视图添加到超级视图。 view.superview?.addSubview(self.playAgainButton)
标签: ios swift uibutton sprite-kit uikit