将 DatePicker 置于 UITextField 的前面

发布于 2024-09-04 05:57:54 字数 615 浏览 5 评论 0原文

当 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 技术交流群。

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

发布评论

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

评论(2

猫卆 2024-09-11 05:57:54

只需将文本字段的输入视图设置为选择器视图即可完成此操作。然后,在编辑时确实开始告诉选择器视图成为第一响应者。像这样,

textField.inputView = pickerView

然后使用在编辑开始时调用的 IBAction

-(IBAction) setPickerViewAsFirstResponder:(id)sender
{
    [pickerView becomeFirstResponder];
}

这完美地工作。您需要实现代码来实际设置选择器视图当前在文本字段中显示的字符串。

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

textField.inputView = pickerView

then using an IBAction called when the Editing Did Begin

-(IBAction) setPickerViewAsFirstResponder:(id)sender
{
    [pickerView becomeFirstResponder];
}

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.

情愿 2024-09-11 05:57:54

这绝对可以完成...只需在 .h 中设置 UIViewController 后实现以下方法,

长话短说,这会覆盖文本编辑之前的键盘加载开始。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    // Make a new view, or do what you want here
    UIDatePicker *pv = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,245,0,0)];
    [self.view addSubview:pv];
    return NO;  
}

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.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    // Make a new view, or do what you want here
    UIDatePicker *pv = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,245,0,0)];
    [self.view addSubview:pv];
    return NO;  
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文