UIPickerView,检测“滚轮”开始和停止?
我刚刚发现,如果我执行以下操作:
- 单击将
UIPickerView
动画化到我的视图中的按钮 - 快速启动轮子滚动到最后一个项目 然后
- 通过按钮关闭视图
然后它还没有尚未选择最后一项。
我通过简单地在 didSelectRow
方法被触发时输出到控制台来尝试此操作,并且当轮子稳定在最后一个项目上时它会触发。
我是否可以检测到车轮仍在滚动,以便我可以延迟检查所选值,直到它稳定为止?
如果重要的话,我正在使用 MonoTouch 进行编程,但是如果您有代码示例,我可以很好地阅读 Objective-C 代码来重新实现它。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
由于动画键不起作用,我编写了这个简单的函数,用于检测 UIPickerView 当前是否正在移动。
它最终返回真正的五层深度。
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.
Swift 4(更新) 版本,带有 @DrainBoy 答案的扩展
Swift 4 (updated) version with extension of @DrainBoy answers
由于
animationKeys
似乎不再起作用,我有另一个解决方案。如果您检查UIPickerView
的子视图,您将看到每个组件都有一个UIPickerTableView
。这个
UIPickerTableView
确实是UITableView
的子类,当然也是UIScrollView
的子类。因此,您可以检查其contentOffset
值来检测差异。此外,其
scrollViewDelegate
默认情况下为 nil,因此我假设您可以安全地设置一个对象来检测scrollViewWillBeginDragging
、scrollViewDidEndDecelerating
等。保留对每个
UIPickerTableView
的引用,您应该能够实现高效的isWheelRolling
方法。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.扩展@iluvatar_GR 答案
Expanded @iluvatar_GR answer
扩展@iluvatar_GR、@Robert_at_Nextgensystems 回答
使用的手势、UIScrollView isDragging 或 isDecelerating。
Expanded @iluvatar_GR, @Robert_at_Nextgensystems answer
Used Gesture, UIScrollView isDragging or isDecelerating.
我认为你可以检查 UIPickerView 是否处于动画状态并等待它停止。此处回答了这个问题链接
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
您可以在选择器上使用 SwipeGestureRecognizer。
我认为这根本不是一个完美的解决方案。
You can use a SwipeGestureRecognizer on the picker.
I assume this is not a perfect solution at all.