yesman yesman - 2 years ago 434
Swift Question

How can I disable Multi Click for UIButton in Swift?

When I click the two

together, It is opening at the same time. My purpose is when I click the single
, the others won't be clickable. I think this is about the multi-touch feature. I just want to use single-touch.

My code :

self.view.multipleTouchEnabled = false
self.view.exclusiveTouch = true

I tried this code in
, but didn't work.

Answer Source

Add @IBOutlets for each of your buttons by control-dragging from each button to the viewController and give them unique names such as button1, button2 and button3.

class ViewController: UIViewController {

    @IBOutlet weak var button1: UIButton!
    @IBOutlet weak var button2: UIButton!
    @IBOutlet weak var button3: UIButton!

Then in viewDidLoad, set the exclusiveTouch property to true for each of the buttons:

override func viewDidLoad() {

    button1.exclusiveTouch = true
    button2.exclusiveTouch = true
    button3.exclusiveTouch = true

This will prevent a second button from being pressed while the pressing of the first one is in process.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download