I will assume that you want your app to be in portrait, as you can make the changes if it is landscape. Add a UIPickerView
to your nib and hook it up to an IBOutlet
. Then, make a button with an IBAction
method that animates the UIPickerView
. Try in the .h file:
@interface MyViewController: UIViewController {
BOOL _pickerIsVisible;
IBOutlet UIPickerView * _picker;
}
- (IBAction)buttonMethod:(UIButton *)aButton;
and in your .m file:
- (void)viewDidLoad; {
[super viewDidLoad];
_pickerIsVisible = NO;
}
- (IBAction)buttonMethod:(UIButton *)aButton; {
if(_pickerIsVisible){
_pickerIsVisible = NO;
[UIView animateWithDuration:2.0f
animations:^{
CGPoint point = _picker.frame.origin;
point.y += 216; // The height of the picker.
_picker.frame.origin = point;
}
completion:^(BOOL finished){
// Do something here if you want.
}];
}
else{
_pickerIsVisible = YES;
[UIView animateWithDuration:2.0f
animations:^{
CGPoint point = _picker.frame.origin;
point.y -= 216; // The height of the picker.
_picker.frame.origin = point;
}
completion:^(BOOL finished){
// Do something here if you want.
}];
}
}
Make sure you set your UIPickerView
in the nib to have a y coordinate of 480, so it is below the view.
Edit: If you want the UIPickerView
to be hooked up and act like the keyboard of a UITextField
or UITextView
, you could always hook it up to the .inputView
property of the UITextField
, and that would work as well.
Hope that Helps!