UISwitch emits superflous or invalid control events while tracking
| Originator: | argentumko | ||
| Number: | rdar://14485185 | Date Originated: | 19-Jul-2013 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | iOS 7+ |
| Classification: | UI/Usability | Reproducible: | Always |
Summary:
The new UISwitch in iOS 7 beta emits invalid or repeating UIControlEventValueChanged events if it is controlled by tracking user touch instead of just tapping. In first case, it emits two successive events with an invalid change if it's switched from "off" to "on" and then back to "off" by dragging the thumb back and forth in a single touch, and in the other case it emits a series of events if a touch that thumb is tracking is cancelled by dragging it far away from the switch.
Steps to Reproduce:
1. Create a new empty application (with just a window, or view controllers - doesn't matter).
2. Add a switch on the window or any of its subviews programmatically or from nib file.
3. Add a target/selector for UIControlEventValueChanged events to this switch.
4. In this target/selector, add a log call to watch the events and, most importantly, the state of the switch at the moment of target/selector call.
5. Run the app and perform one of these actions:
I. Touch and hold the thumb of the switch (it's in "off" state), drag it to the "on" state, then, without releasing the touch, drag it back to the "off state" and release the touch.
II. Touch and hold the thumb of the switch (its state doesn't matter), then drag the touch on ~100 points away from the thumb in the opposite direction from changing the switch state.
Expected Results:
In both cases, switch should not emit any events at all since actual state does not change.
Actual Results:
Case I: at the moment when touch is released, switch emits two successive events and target/selector is called. During the first call, -[UISwitch isOn] for the sender returns YES, and during the second one, the same call returns NO - like if state of the switch has changed back and forth immediately.
Case II: at the moment when touch is cancelled, switch starts emitting repeated events, for each frame of animating back to inactive state, it seems. -[UISwitch isOn] call to sender during each event raising gives the same state - the one which the switch currently has.
Regression:
This behavior does not occur in iOS 6.x. I have no information about this on earlier seeds of iOS 7, though.
Notes:
The switch and event target/selector behave correctly if switch is just tapped to change its state.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Vlas Voloshin
As of iOS 10 beta (14A5261u), an issue still exists partially: dragging the switch thumb in the direction opposite to the value change (e.g. left when the switch is OFF or right when the switch is ON) still generates two value change events, while in fact no events should be generated (as such touch gesture is basically a cancellation of changing the switch value).
Apple Developer Relations
Please verify this issue with the latest iOS 10 beta build and update your bug report at https://bugreport.apple.com/ with your results.
iOS 10 beta (Build: 14A5261v) https://developer.apple.com/download/ Posted Date: Jun 13th, 2016
Vlas Voloshin
As of iOS 8.4 and iOS 9 Seed 2, this issue still exists.
Vlas Voloshin
As of 11A4449d, this issue still remains. Additionally, I now see a regression: "flicking" the switch by a quick swipe may now result in "value changed" event not being generated, though visual representation of the switch changes correctly. This happens not all the time, requires performing some specific swipe. You can use the project I've attached here to reproduce.
Vlas Voloshin
This bug is still present on iOS 7 Seed 5 (build 11A4449a), in the same way I've described above.
Also, I think someone left a debug logging that spams the console when touch events are generated, like this one: AssertMacros: queueEntry, file: /SourceCache/IOKitUser/IOKitUser-920.1.11/hid.subproj/IOHIDEventQueue.c, line: 512
Vlas Voloshin
As of 11A4435d, this bug is only resolved partially. Case 1 (dragging the thumb back and forth) now works as expected, but case 2 (dragging finger away from the switch) still generates series of UIControlEventValueChanged events. Please refer to my original report for details.