swift - 游戏结束风格弹出 View

标签 swift

我很难编写一个弹出 View ,以便在计时器结束后显示在屏幕上。我正在尝试实现在游戏结束时弹出的“游戏结束”样式屏幕,要求您再次玩、重新启动、共享等。目前我可以提示 UIAlertView,但这不是我想要的。我想弹出一个与它类似的“游戏结束”屏幕,因为我想设计它的样式。有任何想法吗?

 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()

最佳答案

您可以创建一个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 文件。

关于swift - 游戏结束风格弹出 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28664433/

相关文章:

ios - 使用 Alamofire 在 Swift 中下载和解析 json

ios - 使用 NSMutableAttributedString 为字符串中的单词添加颜色

swift - Realm 按日期列表内的日期对对象进行排序

string - 你如何检查一个字符串是否是 Swift 中的有效 double

swift - 如何将标签栏背景图像设置为清晰图像

ios - 在 Web View 中点击应用程序 url 方案后如何返回应用程序

swift - 在 Swift 中,为什么同名的实例参数和类函数会产生无效的重声明错误?

ios - 使用数组设置标签文本给出错误 "Cast from ' [String ]' to unrelated ' String' 总是失败

ios - UITableViewCell 中 UIStackView 中的 UICollectionview

swift - 如何避免强制展开变量?