当用户选择UITextField时,如何显示UIDatePicker而不是键盘? [英] How can I show a UIDatePicker instead of a keyboard when a user selects a UITextField?

查看:152
本文介绍了当用户选择UITextField时,如何显示UIDatePicker而不是键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表视图中有一个很好的干净的UI,有一些文本字段供用户填写。其中一个字段是用于用户的生日。

I have a nice clean UI within a table view which has a few text fields for the user to fill out. One of the fields is for the user's birthday.

我想拥有它,以便当用户选择生日字段时,包含UIDatePicker的视图会出现as,就像选择文本字段时不同的键盘一样。

I'd like to have it so that when the user selects the birthday field, a view containing a UIDatePicker would come up as, just like the different keyboards do when selecting a text field.

可以这样做吗?我必须防止文本字段成为第一个响应者(为了避免键盘弹出来),如果之前没有显示任何键盘,我必须将视图动画化。

Can this be done? I would have to prevent the text field from being the first responder (to avoid having the keyboard come up) and I would have to animate the view sliding up if no keyboard was showing before.

呈现视图模式是一个选项吗?如果是这样,我怎么去做呢?从文档看来,模态视图仍占用整个屏幕,我只想使用较低的216像素(键盘和UIDatePicker的高度)。

Would presenting the view modally be an option? If so how would I go about doing it? From the documentation it seems that modal views still take up the whole screen, I just want to use the lower 216 pixels (height of the keyboard and UIDatePicker).

任何一个

推荐答案

我将通过动画处理一个包含UIDatePicker的视图来实现这一点完成和取消按钮)从屏幕底部向上。使用CoreAnimation,这应该很容易。

I would implement this by just animating a view containing the UIDatePicker, a Done, and Cancel button) up from the bottom of the screen. Using CoreAnimation, this should be pretty easy.

这篇关于当用户选择UITextField时,如何显示UIDatePicker而不是键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆