开发者

UISwitch force drag to change setting

开发者 https://www.devze.com 2023-01-10 23:22 出处:网络
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 \'s开发者_StackOverflow社区wipe\' action to prevent the user ac

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 's开发者_StackOverflow社区wipe' 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.


UISwitch is a child of UIResponder. So you can try to use methods like touchesBegan:withEvent:, touchesMoved:withEvent: and touchesEnded: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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号