I'm looking to add some final touches to the user experience of a game I'm writing in Swift. Currently I've got a gameOVerViewController that is activated when the game is over, on that screen the score and highscore are displayed with an interstitial ad after a few seconds.
I've also got a replay
UIButton that unwinds the segue and restarts the game.
What I'm looking for is a timer on the replay button that make the button active after three seconds, similar to what you may see on an interstitial advert where you can see the seconds counting down before you can have any interaction with the object.
--------------- Updated with code
Hello again,
I've partially made the code work, the UIButton
has had it's accesabilitty enabled box unchecked with the below code in my gameOverViewController
file.
class GameOverViewController: UIViewController {
@IBOutlet weak var button: UIButton!
}
override func viewDidLoad() {
super.viewDidLoad()
self.button.enabled = false
NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "enableButton", userInfo: nil, repeats: false)
//lots of code here to bring up google interstitial advert
}
func enableButton() {
self.button.enabled = true
}
The button is correctly greyed out for three seconds then turns blue, however once clicked the viewController
hangs then crashes. The error brings up AppDelegate
with the SIGABRT error. This is the extract from the output field...
20 libdyld.dylib 0x0000000105fa5145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The button is part of a segue that once pressed changes the ViewController
back to GameViewController, here is the code on GameViewController
@IBAction func replay(segue: UIStoryboardSegue) {
}
Without the code that enables the button after three seconds the replay works fine. Any ideas?