Is there a way to stop a UISwitch from toggling state when you tap on the inactive side? I would like a control that forces a deliberate ‘swipe’ action to prevent the user accidentally clicking it. I’ve had a look around but haven’t found any setting that removes the instant toggle on tap.
Is there a way to stop a UISwitch from toggling state when you tap
Share
UISwitch is a child of UIResponder. So you can try to use methods like
touchesBegan:withEvent:,touchesMoved:withEvent:andtouchesEnded:withEvent:to detect user actions.The idea is to set some flag to ‘changes are not allowed’ state, when user began touches. Change it, depending on touch coordinates – for example, change state to ‘changes are allowed’, if user moved touch more than 25 pixels right. And make real changes when touches ended, depending on final flag’s state.