How to prevent a UISwitch from changing state?

I've had the same problem like you. In your valueChanged action method you have to invoke the setOn method with animated set to true. So in swift that would be:

@IBAction func switchValueChanged(sender: UISwitch) {
    sender.setOn(false, animated: true)
}

It might seem counterintuitive since this method is called after switch value changed. But somehow it seems to work.


add a clear color subview to that UISwitch view, cover it and add UITapGestureReconizer to this subview, and all action operations can be triggered in tap action including change the UISwitch view status. Hope it help you!


One unsophisticated solution is just putting a button with the same size and transparent background color in front of the UISwitch control. While it is not the direct answer to your question, it is nice workaround and I always do that with UIImageView.


Why dont u simply set userInteraction to NO

[self.switchButton setUserInteractionEnabled:NO];