I just discovered that if I do the following:
- Click the button that animates a
UIPickerView
into my view - Quickly start the wheel rolling towards, then past, the last item
- Dismiss the view with a button
Then it has not yet selected the last item yet.
I tried this by simply outputting to the console whenever the didSelectRow
method was fired, and it fires when the wheel stabilizes on the last item.
Can I detect that the wheel is still rolling, so that I can delay checking it for a selected value until it stabilizes?
If it matters, I'm programming in MonoTouch, but I can read Objective-C code well enough to reimplement it, if you have a code example that is.
Expanded @iluvatar_GR answer
Swift 4 (updated) version with extension of @DrainBoy answers
You can use a SwipeGestureRecognizer on the picker. I assume this is not a perfect solution at all.
As animation keys don't work, I wrote this simple function that works for detecting if a UIPickerView is currently moving.
It ends up returning true five levels deep.
Since
animationKeys
seems to not work anymore, I have another solution. If you check the subviews ofUIPickerView
, you'll see that there is aUIPickerTableView
for each component.This
UIPickerTableView
is indeed a subclass ofUITableView
and of course ofUIScrollView
. Therefore, you can check itscontentOffset
value to detect a difference.Besides, its
scrollViewDelegate
is nil by default, so I assume you can safely set an object of yours to detectscrollViewWillBeginDragging
,scrollViewDidEndDecelerating
, etc.By keeping a reference to each
UIPickerTableView
, you should be able to implement an efficientisWheelRolling
method.I think you can just check if the UIPickerView is in the middle of animating and wait for it to stop. This was answered here link