我在viewControler上有一个按钮,我想要调出一个UIDatePicker。我想我需要将它动画输入/输出。
到目前为止,我已经设置了按钮,并在我的IB中有了一个单独的视图中的UIDatePicker。我认为让它以模态的方式出现是最有意义的。
需要什么代码来链接UIDatePicker,以便通过单击按钮滑入视图,然后滑出?
谢谢。
发布于 2011-04-14 10:03:04
您希望保持对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要制作动画,只需使用另一种方法将帧更改为原始的“屏幕外”帧即可。
发布于 2013-05-30 19:54:36
你可以省去这个麻烦,把你的UIDatePicker设置成你的UITextField的“键盘”。如下所示:
UIDatePicker *datePicker = [UIDatePicker new];
self.dateField.inputView = datePicker;这样,它的行为就像一个键盘,并根据需要进行动画输入和输出。您可以使用textField委托方法来通知它离开。简单的方法已经够难的了。这就是我的哲学;)
https://stackoverflow.com/questions/5657679
复制相似问题