Вы хотите сохранить ссылку на свой UIDatePicker, а затем вы можете использовать UIView
для анимации ввода и вывода datePicker. Я бы обернул средство выбора в UIView, чтобы вы могли добавить кнопку скрытия или связанные элементы управления.
В вашем заголовочном файле:
@interface MyControllerWithSlidingDatePicker : UIViewController{
//If you use Interface builder, use this
IBOutlet IDatePicker *picker;
//If you aren't using IB, use this
//UIDatePicker *picker;
}
@property (nonatomic, retain) UIDatePicker *picker;
@end
И ваш файл реализации:
#import "MyControllerWithSlidingDatePicker.h"
@implementation MyControllerWithSlidingDatePicker
- (id) init{
self = [super init];
if(self){
//If you use Interface Builder, skip this part.
UIDatePicker *dp = [[UIDatePicker alloc] init];
//Configure your picker
self.picker = dp;
[dp release];
}
return self;
}
- (IBAction)slidePickerIn{
//Position the picker out of site
[self.picker setFrame:CGRectMake(0,self.view.frame.size.height,self.width,self.picker.frame.size.height];
//Add the picker to the view
[self.view addSubview:self.picker];
//This animation will work on iOS 4
//For older iOS, use "beginAnimation:context"
[UIView animateWithDuration:1.0 animations:^{
[self.datePicker setFrame:CGRectMake0,self.view.frame.size.height-self.datePicker.frame.size.height,self.datePicker.frame.size.width,self.datePicker.frame.size.height];
}
}
- (void)dealloc{
[picker release];
[super dealloc];
}
@end
Чтобы оживить, вы просто делаете другой метод, чтобы изменить рамку на исходную "закадровую" рамку.