底部弹出UIPicker? [英] Bottom pop-up UIPicker?
问题描述
当一个动作被调用时,UIPicker是从屏幕底部弹出的,只是一个以某种方式协调的基本UIPickerView? (就像UIActionSheet?)我将如何实现?
Is the UIPicker that pops up from the bottom of the screen when an action is called just a basic UIPickerView that is coordinated in a certain way? (Like a UIActionSheet?) How would I implement that?
推荐答案
这是我使用的动画代码:
Here's animation code, that I use:
- (void)animateDatePicker:(BOOL)show {
CGRect screenRect = self.frame;
CGSize pickerSize = [self.datePickerView sizeThatFits:CGSizeZero];
CGRect startRect = CGRectMake(0.0,
screenRect.origin.y + screenRect.size.height,
pickerSize.width, pickerSize.height);
CGRect pickerRect = CGRectMake(0.0,
screenRect.origin.y + screenRect.size.height - pickerSize.height,
pickerSize.width,
pickerSize.height);
self.datePickerView.frame = pickerRect;
self.backgroundColor = UIColorMakeRGBA( 64, 64, 64, 0.7f - (int)show * 0.7f );
if ( show ) {
self.datePickerView.frame = startRect;
[self.parentViewController addSubviewToWindow:self];
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3f];
[UIView setAnimationDelegate:self];
self.backgroundColor = UIColorMakeRGBA( 64, 64, 64, 0.0f + (int)show * 0.7f );
if ( show ) {
self.datePickerView.frame = pickerRect;
} else {
[UIView setAnimationDidStopSelector:@selector(slideDownDidStop)];
self.datePickerView.frame = startRect;
}
[UIView commitAnimations];
}
datePickerView是一个包含DatePicker的视图:
datePickerView is a view, that contains DatePicker:
self.datePickerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 174.0, 320.0, 286.0)];
self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 70.0, 320.0, 216.0)];
[self.datePicker setDatePickerMode:UIDatePickerModeDate];
[self.datePicker addTarget:self action:@selector(pickerValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.datePickerView addSubview:self.datePicker];
parentViewController应该实现addSubviewToWindow方法:
parentViewController should implement addSubviewToWindow method:
- (void)addSubviewToWindow:(UIView *)addView {
[self.view addSubview:addView];
}
UIColorMakeRGBA:
UIColorMakeRGBA:
#define UIColorMakeRGBA(nRed, nGreen, nBlue, nAlpha) [UIColor colorWithRed:(nRed)/255.0f green:(nGreen)/255.0f blue:(nBlue)/255.0f alpha:nAlpha]
slideDownDidStop是一种方法,将在datePicker成功滑下后调用。
slideDownDidStop is a method, that will be called after datePicker slide down successfully.
所以,总结一下 - 你有MyViewController,它有
So, just to summarize - you have MyViewController, that have
MyDatePickerView *myDatePicker;
字段。
MyDatePickerView是一个自定义class,有UIDatePicker * datePicker字段,MyViewController * parentViewController和animateDatePicker方法。
MyDatePickerView is a custom class, that have UIDatePicker *datePicker field, MyViewController *parentViewController and animateDatePicker method.
当你在MyViewController上执行某些操作时(例如,某些按钮的UIControlEventTouchUpInside),你应该调用
When you perform some action on MyViewController (for example, UIControlEventTouchUpInside for some button), you should invoke
[myDatePicker animateDatePicker:YES];
如果您有任何疑问,请与我们联系。
Please let me know if you have questions.
更新:
这是一个小的示例 。
这篇关于底部弹出UIPicker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!