Home > Blockchain >  Only allow touch after a certain time
Only allow touch after a certain time

Time:10-28

For the game I am creating, I have a little animation of sorts at the beginning when the start button is pressed. However being able to touch the screen interferes with this animation. Is there any way I can have the user not be able to interact with the screen until (lets say 10 seconds) after the start button is clicked? Here is my code for the current users touch:

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
   
    for touch in touches {
        
        let location = touch.location(in: self)
        player.position.x = location.x
        player.position.y = -300//location.y
        
    }
}

CodePudding user response:

Stop ClickEvent in entire screen.

view.isUserInteractionEnabled = false

Continue ClickEvent after some time, i.e.: 10 Sec.

DispatchQueue.main.asyncAfter(deadline: .now()   10) { 
    self.view.isUserInteractionEnabled = true 
}

CodePudding user response:

You can disable user interaction while clicking on the screen and enable it after 10 second as-

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
   
    for touch in touches {
        
        let location = touch.location(in: self)
        player.position.x = location.x
        player.position.y = -300//location.y
        
    }
    self.view.isUserInteractionEnabled = false
    DispatchQueue.main.asyncAfter(deadline: .now()   10) {
         self.isUserInteractionEnabled = true
    } 
}
  • Related