iPhone UIDate弹出窗口? [英] iPhone UIDate popup?

查看:158
本文介绍了iPhone UIDate弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android设备上,如果我想要一个日期或号码选择器弹出,一个窗口具有弹出窗口的控制。我在iPhone上没有找到办法吗?什么是推荐的方法来处理这些对象?

On an Android device, if I wanted a date or number picker to popup, a window with the control on the popup. I haven't found a way to do this on iPhone? What is the recommended way to handle these objects?

编辑:我已经使用 Interface Builder ,但它是静态的,不会弹出。

I have added a UIDatePicker using Interface Builder, but it's static and doesn't popup. What code would I use to make this popup?

推荐答案

iOS 3.2及更高版本



UIResponder具有一个 inputView 属性,可以与UITextField和UITextView一起使用任何视图(包括UIDatePicker)替换标准键盘。 (另请参见: inputAccessoryView ,可用于在键盘上方放置工具栏。)

iOS 3.2 and Later

UIResponder has an inputView property which can be used with UITextField and UITextView to replace the standard keyboard with any view you please, including a UIDatePicker. (See also: inputAccessoryView, which can be used to put a toolbar above the keyboard.)

请参阅数据输入的自定义视图

See Custom Views for Data Input in the iOS documentation for more details.

如果您希望选择器弹出键盘是的,你必须自己去做。这不是太毛茸茸

If you want the picker to pop up as the keyboard does, you have to do this yourself. It's not too hairy.

要使选择器视图从屏幕底部滑入位置:

To make the picker view slide into position from the bottom of the screen:

pickerView.frame = <offscreen, just below the main view>
[UIView beginAnimations:@"PickerUp" context:nil];
pickerView.frame = <onscreen, at the bottom of the view>;
[UIView commitAnimations];

完成后,让选择器视图滑动:

To make the picker view slide away when done:

[UIView beginAnimations:@"PickerDown" context:nil];
pickerView.frame = <offscreen, just below the main view>
[UIView commitAnimations];

键盘由自动处理,因为它由UITextView / UITextField管理;因为你想要一个自定义输入视图,你必须编写代码来自己管理。

The keyboard is handled automagically because it is managed by UITextView/UITextField; since you want a custom input view, you have to write the code to manage it yourself.

如果你走这条路线,你应该看看关于 becomeFirstResponder 和整个UIResponder链,所以您的自定义控件与系统和其他文本字段一起播放。

If you go this route, you should look read the documentation about becomeFirstResponder and the whole UIResponder chain, so your custom control plays well with the system and other text fields.

如果您想要选择器上方的工具栏,只需创建一个包含工具栏,选择器和其他任何您想从下方弹出的其他UIView。然后将该容器视图动画化,而不是选择器。

If you want a toolbar above the picker, just create a generic UIView containing the toolbar, picker, and anything else you want to pop up from below. Then animate that container view in, instead of just the picker.

这篇关于iPhone UIDate弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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