I’ve an previous app which had been working fantastic until iOS 26 got here out. In my app, I’m utilizing the .valueChanged
occasion of UISlider
to get the section
and do various things if it is .started
, .moved
, or .ended
.
It is a widespread answer: Methods to detect the top of UISlider drag?
Beneath is my easy instance:
import UIKit
import SnapKit
class ViewController: UIViewController {
let label = UILabel()
let slider = UISlider()
override func viewDidLoad() {
tremendous.viewDidLoad()
let stackView = UIStackView(arrangedSubviews: [label, slider])
stackView.axis = .vertical
stackView.spacing = 20
view.addSubview(stackView)
stackView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.horizontalEdges.equalToSuperview().inset(30)
}
label.textAlignment = .middle
slider.isContinuous = true
slider.minimumValue = 0
slider.maximumValue = 100
slider.addTarget(self, motion: #selector(sliderValueChanged(sender:occasion:)), for: .valueChanged)
}
@objc func sliderValueChanged(sender: UISlider, occasion: UIEvent) {
print("Slider: (slider.worth), (occasion)")
label.textual content = "Worth: (sender.worth)"
swap occasion.allTouches?.first?.section {
case .started:
print("started")
case .moved:
print("moved")
case .ended:
print("ended")
case .cancelled:
print("cancelled")
default:
break
}
}
}
This had been working fantastic earlier than. However in iOS 26, the occasion
being handed to my sliderValueChanged
perform is odd. It isn’t nil
however it’s additionally not a correct occasion. For instance, the print
assertion simply prints an empty textual content for the occasion
. And setting a break assertion at that time reveals it as beneath:
Due to this, in iOS 26, the occasion.allTouches
is at all times nil. So, I’m unable to determine what occasion section it’s.
Is that this a bug? How can I workaround it?
I did discover that if I swap from .valueChanged
to .allEvents
, then I get the occasion for started
and moved
section. Nevertheless, I don’t get the ended
or cancelled
section.
How can I get these phases too?
EDIT:
Seems to be like this may be a bug: