iPhone:我可以让UIDatePicker出现在UIKeyboard的顶部吗?(iPhone: Can I make a UIDatePicker appear on top of a UIKey

编程入门 行业动态 更新时间:2024-10-25 02:24:16
iPhone:我可以让UIDatePicker出现在UIKeyboard的顶部吗?(iPhone: Can I make a UIDatePicker appear on top of a UIKeyboard?)

我想做什么:

我有一个标准的UITableView,有几个UITextFields和一些显示时间/日期的单元格。 基本上,它是用户可以输入文本和日期的表单。

它是如何工作的:

首先,没有显示键盘或日期选择器。 如果首先选择文本字段,则弹出键盘。 反之亦然,日期选择器(弹出类似的动画)。 如果最初选择了文本字段,然后用户选择了一个时间单元格,则UIKayboard应该变成日期选择器(无动画)。 同样应该在相反的情况下发生。

什么不起作用:

一切都很好 - 除了我上面列出的最后一步。 基本上,我无法弄清楚如何在键盘显示任何内容。

我的方法只是同时为键盘/日期设置动画,但相应地设置日期选择器的“隐藏”属性。

-

关于如何在键盘前添加东西的任何想法? 添加键盘后,我可以在所有内容上创建另一个窗口吗? 或者,使用accessoryView属性但以某种方式转置框架?

否则,有没有其他方法可以实现我的最初目标?

谢谢 :)

What I'm trying to do:

I've got a standard UITableView, with several UITextFields and a few cells showing a time/date. Basically, it's a form where users can input both text and dates.

How it's meant to work:

At first, neither the keyboard or date picker is shown. If a text field is selected first, the keyboard pops up. Vice versa for a date picker (which pops up with a similar animation). If originally a text field was selected, and then the user selects a time cell, the UIKayboard should turn into a date picker (no animation). Likewise should happen when the other way around.

What's not working:

Everything works great - except for the last step I listed above. Basically, I can't figure out how to present anything on top of the keyboard.

My method was just to animate both the keyboard/date up at the same time, but set the 'hidden' property for the date picker accordingly.

-

Any ideas as to how I might add something in front of the keyboard? Could I create another window on top of everything just after adding the keyboard? Or, use the accessoryView property but transpose the frame somehow?

Otherwise, are there any alternate ways I could achieve my original goal?

Thanks :)

最满意答案

比监听键盘通知更容易实现UITextField是UIResponder的子类,这意味着它具有inputView属性。 您可以简单地创建一个UIDatePicker ,将其设置为textfield的inputView,然后就完成了。 (加上你需要做的任何事情来实际从选择器中提取日期)。

这种方法的唯一缺点是虽然它在iPhone上的纵向方向非常有效,但你需要做一些工作,让事情在风景和iPad上看起来正确。 但是,无论如何,这都是你必须要做的事情。

Even easier than listening for the keyboard notifications is to realize that UITextField is a subclass of UIResponder, which means it has an inputView property. You can simply create a UIDatePicker, set it to be your textfield's inputView, and you're done. (plus anything you need to do to actually extract the date from the picker).

The only downside of this approach is that while it works extremely well for the portrait orientation on iPhone, you'll need to do a bit of work getting things to look right in landscape and on the iPad. However, it's the same sort of stuff you'd have to do anyway.

更多推荐

本文发布于:2023-07-27 15:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292404.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:出现在   UIDatePicker   iPhone   UIKeyboard   top

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!