将 DatePicker 置于 UITextField 的前面
当 UITextField 是firstResponder 时,我想将 UIDatePicker 置于前面(屏幕的底部),而无需“向下键盘”(不调用 UITextField resignFirstResponder)。
目的是像 UITextField 的 UIKeyboard 一样进行处理,当它成为 FirstResponder 时,几乎所有内容都会弹出。 modalViewController 似乎只能全屏。
- showDatePicker:(id)sender {
if([taskName isFirstResponder]) [taskName resignFirstResponder];
[self.view.window addSubview: self.pickerView];
// size up the picker view and compute the start/end frame origin
(...)
[UIView commitAnimations];
}
此示例是键盘向下移动、DatePicker 向上移动的动画,位于后面而不是前面。
你知道解决办法吗?一段代码将受到欢迎。提前致谢。
When an UITextField is firstResponder, I would like to bring to front an UIDatePicker (bottom part of the screen) without the "going down keyboard" (no call to UITextField resignFirstResponder).
The aim is to process like UIKeyboard of UITextField which pop-up on nearly everything when it becomeFirstResponder. modalViewController seems to be fullscreen only.
- showDatePicker:(id)sender {
if([taskName isFirstResponder]) [taskName resignFirstResponder];
[self.view.window addSubview: self.pickerView];
// size up the picker view and compute the start/end frame origin
(...)
[UIView commitAnimations];
}
This example is an animation of keyboard going down, and DatePicker going up, behind and not in front.
Do you know a solution ? A piece of code would be welcome. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将文本字段的输入视图设置为选择器视图即可完成此操作。然后,在编辑时确实开始告诉选择器视图成为第一响应者。像这样,
然后使用在编辑开始时调用的 IBAction
这完美地工作。您需要实现代码来实际设置选择器视图当前在文本字段中显示的字符串。
This is simply done by setting the input view of the text field to the Picker View. Then, on Editing did begin tell the picker view to becomeFirst responder. Like this
then using an IBAction called when the Editing Did Begin
This works perfectly. You'll need to implement code to actually set what the picker view is currently showing to be a string in the text field still.
这绝对可以完成...只需在
.h
中设置UIViewController
后实现以下方法,长话短说,这会覆盖文本编辑之前的键盘加载开始。
This definitely can be done... simply implement the method below after setting
UIViewController <UITextFieldDelegate>
in your.h
Long story short, this overrides the keyboard loading before text editing begins.