0

I'm having a hard time coding a pop up view to display on the screen after my timer has ended. I'm trying to accomplish that "Game Over" style screen that pops up at the end of a game that asks you to play again, restart, share etc. Currently I am able to prompt the UIAlertView but thats not what I want. I want to popup a "Game Over" screen similar to it because I want to style it. Any ideas?

 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()
Tycoon
  • 293
  • 2
  • 3
  • 10

1 Answers1

1

You can create an UIView and then show it up animated. Like that:

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

As you see, first you create a UIView with 0 width and 0 height. After that you call animateWithDuration and resize it in 2 seconds to 100 width and 100 height.

Then you can add any buttons etc you want. You can also make a .xib file for your UIView.

Christian
  • 22,585
  • 9
  • 80
  • 106
  • That easy huh? Haha thanks Christian! One other thing though, I want to add button to it. How do I add button to it when I only create a UIView thats 0x0? And are there any other animations I can use for it? – Tycoon Feb 23 '15 at 00:06
  • Well you also can scale it and use that answer: http://stackoverflow.com/questions/14697714/scale-uiview-and-all-its-children – Christian Feb 23 '15 at 00:08