UIPickerView 卡在行之间?

发布于 2024-11-01 14:55:53 字数 306 浏览 3 评论 0原文

我在使用 UIPickerView 时注意到一个问题,我想知道是否有人以前遇到过它:有时滚动其中一个轮子时,它会卡在两行之间(触摸结束后),并且无限期地保持这种状态。再次稍微拖动方向盘并释放总是可以解决问题,但无论如何,我很困惑为什么会发生这种情况。在模拟器和实际设备上进行测试时都会发生这种情况。

问题不在于卡住时必须重新调整轮子的烦恼,而在于有时当它非常接近选择一行(但实际上尚未选择它)时它会卡住,这可以给用户感觉他们已经选择了给定的行,但实际上他们没有选择。

其他人是否也遇到过这种情况?如果是,有办法解决吗?

谢谢,

克里斯

I've noticed a problem when using UIPickerView, and I'm wondering if anyone has ever encountered it before: Sometimes when scrolling one of the wheels, it gets stuck between two rows (after touches have ended), and just stays like that indefinitely. Dragging the wheel again slightly and releasing always corrects the problem, but regardless, I'm puzzled as to why this is happening in the first place. It occurs when testing both in the simulator and on an actual device.

The problem isn't so much the annoyance of having to re-adjust the wheel when it gets stuck, but rather that sometimes it gets stuck when it's extremely close to selecting a row (but hasn't actually selected it) which can give the user the impression that they have chosen a given row, when really they haven't.

Has this happened to anyone else, and if so, is there a way to fix it?

Thanks,

Chris

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

许一世地老天荒 2024-11-08 14:55:54

仍然没有找到解决这个问题的好方法...我能想到的最好的解决方案是在 pickerView:didSelectRow:inComponent: 方法中包含以下行:

[pickerView selectRow:[pickerView selectedRowInComponent:0] inComponent:0 animated:YES];

这将使指定的组件回滚到正确的行,确保用户始终看到所选内容的准确表示,但是,当您认为组件将停止在某一行上,只是看到它向后动画时,有时看起来很奇怪停止前朝相反方向行驶。

Still haven't figured out a good way to solve this... the best solution I've been able to think of is including the following line in the pickerView:didSelectRow:inComponent: method:

[pickerView selectRow:[pickerView selectedRowInComponent:0] inComponent:0 animated:YES];

This will make the specified component roll back onto the correct row, ensuring that the user is always seeing an accurate representation of what's selected, however it sometimes looks strange when you think the component is going to stop on a certain row, only to see it animate backwards in the opposite direction before stopping.

画中仙 2024-11-08 14:55:54

我有一个与此非常相似的问题。 UIPickerView 将在行之间滚动并停止。通常,此视图不会在行之间停止,即使您尝试将其停止在两个项目之间,它也会自行滚动到下一行。我有许多应用程序没有显示问题,即使它们使用相同的代码来实例化 UIPickerView。

经过大量调查后,我发现我的问题是 CPU 使用率过高。我的应用程序是一个 OpenGL 游戏,因此我有一个尽可能快地运行的游戏循环来更新帧。诚然,我的游戏受 CPU 限制,无法达到完整的帧速率。我让游戏在后台运行,同时弹出 pickerView 以允许用户进行选择。这似乎没有为 UIPickerView 留下任何 CPU 来检测它已在行之间停止并将其自身拉到最近的行。

我的简单解决方案是在选择器视图打开时暂停游戏。

我看到这个答案晚了一年,但我花了一段时间才弄清楚,所以希望它能对某人有所帮助。

I had an issue very similar to this. The UIPickerView would scroll and stop between rows. Normally this view will not stop between rows it will scroll itself to the next row even if you try to stop it in-between two items. I have many apps that did not show the problem even though they used the same code to instantiate UIPickerView.

After much investigation I found my problem was over usage of CPU. My application is an OpenGL game, so I have a game loop running as fast as possible to update the frames. Admittedly my game was CPU bound and not achieving a full frame rate. I was leaving the game running in the background while the pickerView popped up to allow the user to make a selection. This seems to have left no CPU for the UIPickerView to detect it had stopped between rows and pull itself to the nearest row.

My simple solution is to pause the game while the picker view is up.

I see this answer is a year late, but it took me a while to figure out so hope it helps someone.

追星践月 2024-11-08 14:55:54

我想我已经明白了。当您在加载中使用 UIPickerView 的视图时,您需要设置选择器委托,如下所示:

picker.delegate = self;

这应该可以解决问题并导致选择器自动以某个值为中心,而不是在行之间浮动。

I think I've figured it out. When the view that you are using the UIPickerView in loads, you need to set the pickers delegate, like this:

picker.delegate = self;

That should fix the issue and cause the picker to automatically center on a value rather than floating between rows.

梦回旧景 2024-11-08 14:55:54

您应该在 pickerview 委托方法中检查子视图的框架 (pickerView:viewForRow:forComponent:reusingView:)。框架高度不应超过内容视图的高度。

you should check frames of the subviews in pickerview delegate method (pickerView:viewForRow:forComponent:reusingView:). frames height should should not exceed from content view's height.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文