0

I was wondering if there was a way to force interrupt an UISwitch dragging action? (seems dirty)

The problem: On value change, my UISwitch updates the state and sets .isUserInteractionEnabled to false, so further taps aren’t processed until async operation complete and state is then updated (unlocking the UISwitch). In the case where the user switches the UISwitch by dragging it (tap and hold), it sets .isUserInteractionEnabled to false, but the user stays in control of the switch while holding the finger, and can then flip the UISwitch as much he wants and bypass .isUserInteractionEnabled.

When using a random UISwitch in one of the iPhone Settings menu, you can also drag and drop a UISwitch, but at some point the gesture/drag is cancelled and you lose control over it. I don’t see anything to do that in the public API of UISwitch?

Or maybe I shouldn’t use valueDidChange()? I don't see another reliable alternative.

Edit: A TL;DR version

The problem is: if the user hold his tap, even by disabling userInteractions he can still move the switch as long as he hold the initial tap.

Alex C
  • 29
  • 1
  • 4
  • I don't get your issue. If the value didn't change surely you wouldn't run the async task? Like only when the user has changed the switch would your run your async and this point lock the switch by disabling interactions? Please provide some code to make this more clear! – Anters Bear Jul 12 '18 at 09:59
  • I can't reproduce. In settings, I can drag a switch back and forth as much as I want. Are you testing on device or simulator? Dragging tends to behave differently. – regina_fallangi Jul 12 '18 at 11:27
  • @AntersBear The issue it stated above: when using a UISwitch, setting `.isUserInteractionEnabled` to false will prevent new tap on the switch, but disabling it while the user is holding the control won't release the hold. So you end up in a situation where the UISwitch.isUserInteractionEnabled IS false, but the user can still switch the UISwitch – Alex C Jul 12 '18 at 11:32
  • @regina_fallangi Yes I'm aware of that, using device. Take something that starts an async operation, a VPN connection UISwitch for example (can reproduce 100%) edit: grammar – Alex C Jul 12 '18 at 11:33
  • Could not reproduce on VPN connection UISwitch -> https://youtu.be/Jdh7Qsrxz9Q – regina_fallangi Jul 12 '18 at 11:44
  • @regina_fallangi yhea weirdly enough it's as you described here, I should have been more precise: see General > VPN > use the switch there. The switch doesn't move visually (get locked?) but I can still feel the haptic feedback from the device (there is something weird going on!) – Alex C Jul 12 '18 at 13:55
  • Look under in the UITableView, there is a cell called `General`, clic that, go to `VPN` after and you'll have a more techy menu – Alex C Jul 12 '18 at 14:06
  • Still can not reproduce what you are talking about -> https://youtu.be/T3pAELz58qQ – regina_fallangi Jul 12 '18 at 14:24
  • @regina_fallangi Interesting... I just reproduce the problem here, but can't upload the video as I don't know how to blur some element out of it... It doesn't behave the same on my devices, no idea why. I do the same as you, except that at some point the switch don't move anymore. Could it be a difference in the VPN profiles? I don't think so, because I tried with 3 devices and 4 differents profiles (NordVPN and house made ones), I can reproduce 100%, on all devices, all profiles. Weird. All on ios 11.4 – Alex C Jul 12 '18 at 14:50
  • I can only reproduce when I lift my finger and try to tap again. If I do not lift my finger, I can drag every time. Tried in iPhone X, iPhone SE and iPhone 8S. All on 11.4, fresh install, no special settings. – regina_fallangi Jul 12 '18 at 14:55
  • You probably want to take a look at this answer, though: https://stackoverflow.com/questions/19628310/ios7-uiswitch-its-event-valuechanged-calling-continuously-is-this-bug-or-what – regina_fallangi Jul 12 '18 at 14:58
  • Thanks for such dedication in testing this little problem @regina_fallangi I'll try that question thing tomorow as I don't have an XCode available around right now – Alex C Jul 12 '18 at 15:26
  • @regina_fallangi the above question is not related actually. The problem is really simple: if the user hold his tap, even by disabling userInteractions he can still move the switch as long as he hold the initial tap – Alex C Jul 13 '18 at 07:13

0 Answers0