如何像键盘一样呈现选择器视图?
我希望当我按下按钮(就像键盘一样)时显示 UIPickerView,然后在用户点击屏幕上的任意位置时消失。我该怎么做?谢谢。
更多背景信息:我在 UITableViewCell 中有一个名为 Months 的 UITextField。现在对我来说最好的选择是在那里放置一个 UIPikcerView ,用户可以更轻松地选择月份,而不必输入它(这是更好的方法)。但 UIPickerView 在 UITableViewCell 中看起来真的很难看,更不用说我无法改变它巨大的尺寸。那么这种情况我该怎么办呢?
I want a UIPickerView to show up when I press a button (just like keyboard) and then go away when user taps anywhere on the screen. How can I do this? Thanks.
A bit more background: I have a UITextField called months in UITableViewCell. Now the best option for me is to put a UIPikcerView there and it will be easier for the user to just chose the month rather than having to type it out (and it's the better way). But UIPickerView looks really ugly in a UITableViewCell, not to mention I can't change it's gigantic size. So what should I do in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是您应该如何将 UIPickerView 用于 UITableView 中的文本字段。
现在
对于 datePickerValueChangedd
在 textFieldDidEndEditing:
并退出 UIDatePicker,将 UIView 设置为 UIControl 并
This is how you should use UIPickerView for a textField in a UITableView.
}
And for datePickerValueChangedd
Now in the textFieldDidEndEditing:
And to resign UIDatePicker, set the UIView as a UIControl and
我认为您需要将 UIPickerView 放在可视屏幕“外部”,并在按下按钮时为其设置动画。我不太确定摆脱它的最佳方法是什么,但您可能可以在选择器可见时监听父视图上的点击,然后将其动画化。
I think that you need to put your UIPickerView "outside" the viewable screen and animate it in when the button is pressed. I'm not really sure what the best way to get rid of it would be but you could probably listen for a tap on the parent view when the picker is visible and then animate it back out.