I'm making an application where two buttons are moving. The first moves immediately and the second one moves after 1 second. What's happening now in my application is that when I click the start button before one second has passed, it shows two of the second button moving. I believe what I would have to do is that when the button is clicked, I would have to cancel the dispatch_after
, but when I try to do this by writing this code:
let time1 = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW),1 * Int64(NSEC_PER_SEC))
dispatch_after(time1, dispatch_get_main_queue()) {
// code of second button moving
}
if time1 == true
{time1 = false}
it says that I cannot assign this to a dispatch_time
. What should I do?
This is the complete code if this helps you:
@IBAction func startbutton(sender: UIButton) {
// code for moving the first button
let time1 = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW),1 * Int64(NSEC_PER_SEC))
dispatch_after(time1, dispatch_get_main_queue()) {
// code of second button moving
}
if time1 == true
{time1 = false}
}