可以取消UIPickerView动量动画吗?
我正在尝试使用 UIPickerView 设置 UI,该 UIPickerView 是根据 UITableView 中选定的行填充的。本质上,它与您在“开始”和“开始”中看到的用户界面相同。用于在日历应用程序中添加事件的结束屏幕。
http://raoli.com/files/uipicker.png
我有我的数据源和委托的设置,以便选择器根据选择进行填充并正确更新我的模型......大多数时候。
我遇到的一个问题是,当有人轻弹选取器视图,然后更改表视图中的选择时,UIPickerViewDelegate 尝试记录表视图中新选择的更改,而不是原始选择。很明显,在我的代码中为什么会发生这种情况,我有一些想法来重新设计我的代码以更好地表现,但我想我应该看看苹果在他们的用户界面中做了什么。
当您在选择器完成旋转之前轻拂选择器并切换时间时,旋转会立即停止,选择器会更新为新时间类型的值,而原始时间类型保持不变。我没有看到任何取消动画的方法,但我可能是错的。我希望我是错的,因为这会让我的生活更轻松。
我可以看到的另一种选择是每个属性都有不同的 UIPickerViews 并将它们切换出来。因此,显然,Apple 示例将有 2 个 UIPickerView 实例。这只会创建其他需要完成的工作,我想我会看看是否有一种方法可以用最少的视图来完成它。
更新 Aaron 的想法显示出一些希望,但看起来有许多关于如何根据选择器的状态将消息传递给委托的边缘情况,主要是选择器当前是否正在动画。由于似乎无法确定选取器当前是否正在旋转(至少通过公共 API),因此尝试解决可能的配置似乎存在问题。我最终使用了多个选择器,当所选属性更改时切换选择器的可见性,并忽略来自现在隐藏的 UIPickerView 实例的委托消息。
I'm trying to setup a UI with a UIPickerView that's populated based on the selected row in a UITableView. Essentially, it's the same UI you see in the Start & End screen for adding an event in the Calendar app.
http://raoli.com/files/uipicker.png
I've got my data source and delegate's setup so it the picker gets populated based on the selection and properly updates my model... most of the time.
The one hitch I'm getting is when somebody flicks the picker view and then changes the selection is in the table view, the UIPickerViewDelegate tries to records the changes against the new selection in the table view, not the original selection. It's obviously in my code why this happens and I have some ideas for reworking my to better behave, but I figured I'd see what Apple was doing in their UI.
When you flick the picker and switch the time before the picker finishes rotating, the rotation is immediately stopped, the picker updates to the value for the new type of time, and the original type of time remains unchanged. I'm not seeing any way to cancel the animation, but I could be wrong. I hope I'm wrong, since it would make my life easier.
The other alternative I could see is different UIPickerViews for each attribute and switching them out. So, obviously, the Apple example would have 2 UIPickerView instance. That just creates other work that needs to be done and I thought I'd see if there was a way to do it with a minimal number of views.
Update Aaron's idea showed some promise, but it looks like there are a number of edge cases about how messages get delivered to the delegate based on the state of the picker, primarily whether or not the picker is currently animating. Since there seems to be no way to determine if the picker is currently spinning (at least via public APIs), trying to work around the possible configurations seemed problematic. I ended up going with multiple pickers, toggling the visibility of the pickers when the selected attribute changes, and ignoring delegate messages from now-hidden UIPickerView instances.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为
会是一个很好的候选人。如果
animated
为NO
,它应该立即显示您想要的内容而无需移动。当您决定设置数据时,调用选取器视图上的方法以反映该设置。我希望它会覆盖任何当前的动画或惯性效果,并且希望您不会在委托中收到
didSelectRow:
。如果您这样做,可能有必要忽略它。I think
would be a good candidate. If
animated
isNO
it should display what you want immediately without moving.When you decide the data is set, call the method on the picker view to reflect that setting. I expect it will override any current animation or inertia effect and hopefully you will not receive a
didSelectRow:
in the delegate. If you do it might be necessary to ignore it.