UIDatePicker valueChanged as wheels spin?

2019-05-19 06:11发布

问题:

I’m using a UIDatePicker to update UILabel with a date, but I’m noticing that the valueChanged event is only called when the wheels stop spinning.

Ideally if the user flicks a column, I’d like the date in the label to update continuously as the wheel spins, for a realtime sense of feedback.

Is this possible?

回答1:

This is an extreme workaround, but...

If you use a UIPickerView instead of a UIDatePicker (which, granted, would entail re-implementing most of the DatePicker), you can detect the wheel spinning in the pickerView:viewForRow:forComponent:reusingView: delegate method. If there are more rows than can be displayed at once, this will be called every time the wheel moves.