views:

726

answers:

2

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.

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.

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).

Any one have any tips on how to go about doing this?

+1  A: 

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.

Ben Gottlieb
How would I go about doing this? I have a view controller/view designed in IB, but I don't know what to do next. Do I add the view as a subview to the currently displayed view and then animate it somehow? I'm not sure how UIViews relate to CALayers for animation.
Ben S
Nevermind. I was able to figure it out. I add the view that contains the date picker to the window and animated it using a `[UIView beginAnimations]` block
Ben S
+1  A: 

Why are you using a text field if you don't want to accept user input from a keyboard? Instead use a UILabel subclass (where you override the touchesBegan/Ended:withEvent: set of methods to show the UIDatePicker) or a UIButton (where your action is a method which slides up the UIDatePicker).

Martin Gordon