如何使用UIDatePicker?
我在 viewControler 上有一个按钮,我想调出 UIDatePicker。我想我需要将其动画化。
到目前为止,我已经完成了按钮设置,并在 IB 中的单独视图中拥有了 UIDatePicker。我认为以模态的方式提出它是最有意义的。
需要什么代码才能链接 UIDatePicker 通过单击按钮滑入视图,然后滑出?
谢谢。
I have a button on a viewControler that I want to bring up a UIDatePicker. I think I will need to animate it in/out.
So far I have the button setup and have the UIDatePicker in my IB in a separate view. I think having it come up modally would make the most sense.
What code is necessary to link the UIDatePicker to slide into view with the click of the button, then slide out?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以省去麻烦,并将 UIDatePicker 设置为 UITextField 的“键盘”。像这样:
这样它的作用就像键盘一样,并根据需要进行动画输入和输出。您可以使用 textField 委托方法来告诉它消失。简单的方法已经够难的了。这就是我的哲学;)
You could save yourself the trouble and set your UIDatePicker as the "keyboard" for your UITextField. Like so:
This way it acts just like a keyboard and animates in and out as needed. You use the textField delegate methods to tell it to go away. The easy way is hard enough. That's my philosophy ;)
您想要维护对 UIDatePicker 的引用,然后可以使用 UIView 来动画显示 datePicker 的进出。我会将选择器包装在 UIView 中,以便您可以添加隐藏按钮或关联的控件。
在你的头文件中:
以及你的实现文件:
要制作动画,您只需使用另一种方法将框架更改为原始的“屏幕外”框架。
You want to maintain a reference to your UIDatePicker and then you can use
UIView
to animate the datePicker in and out. I would wrap the picker in a UIView so you can add a hide button or associated controls.In your header file:
And your implementation file:
To animate out, you just make another method to change the frame to original "offscreen" frame.