游戏结束样式弹出视图

时间:2015-02-22 23:03:16

标签: swift

我的计时器结束后,我很难对弹出视图进行编码以显示在屏幕上。我试图完成那个" Game Over"在游戏结束时弹出的样式屏幕,要求您再次播放,重新启动,共享等。目前我能够提示UIAlertView但这不是我想要的。我想弹出#34; Game Over"屏幕类似于它,因为我想要它的风格。有任何想法吗?

 let alert = UIAlertView(title: "Game Over", message:"Try again...", delegate: nil, cancelButtonTitle: "Cancel")

        alert.addButtonWithTitle("Restart")
        alert.addButtonWithTitle("Share")
        alert.addButtonWithTitle("Rate")
        alert.show()

        timer.invalidate()

1 个答案:

答案 0 :(得分:1)

您可以创建UIView,然后将其显示为动画。像那样:

var gameOver = UIView(frame: CGRectMake(100, 100, 0, 0))
gameOver.backgroundColor = UIColor.redColor()
self.view.addSubview(gameOver)

//Call whenever you want to show it and change the size to whatever size you want     
UIView.animateWithDuration(2, animations: {
   gameOver.frame.size = CGSizeMake(100, 100)
})

如您所见,首先创建一个宽度为0且高度为0的UIView。之后,您拨打animateWithDuration并在2秒内将其调整为100宽度和100高度。

然后你可以添加你想要的任何按钮等。您还可以为您的UIView制作.xib文件。

相关问题