Post

Replies

Boosts

Views

Activity

Reply to UISlider valueChanged has uninitialized UIEvent
Same issue here. There is not much to be done until Apple fixed their framework, but I'd like to share my workaround. Unfortunately, using UIControl.Event instead of UIEvent does not work as advertised. The call just typecasts the pointer (UIEvent*)nil to the value UIControl.Event; that explains why the event always results in UIControlEvents(rawValue:0). My event handler used to look like this: @IBAction internal func sliderValueChanged(_ sender: Any, forEvent event: UIEvent) { if let touchEvent = event.allTouches?.first { switch touchEvent.phase { case .began: ... case .moved: ... case .ended: ... default: break } } } Since the event is not much of any help anymore, I've replaced the old handler with three distinct ones: @IBAction internal func sliderValueChanged(_ sender: Any, forEvent event: UIEvent) { ... } @IBAction func sliderDidBeginValueChange(_ sender: Any) { ... } @IBAction func sliderDidEndValueChange(_ sender: Any) { ... } The handler sliderDidBeginValueChange is connected to "Touch Down" and the handler sliderDidEndValueChange is connected to "Touch Cancel", "Touch Up Inside" and "Touch Up Outside". This allows to mimic the old behaviour for now.
Topic: UI Frameworks SubTopic: UIKit Tags:
Oct ’25