1
我想在用户单击按钮时将UIDatePicker添加到UIView。我有一个动画设置,从底部向上滑动UIView。如果我将UIDatePicker添加到ViewControllers视图,则DatePicker将正确显示。但是,如果我将DatePicker添加到UIView,那么日期选取器根本不显示。在运行时将UIDatePicker添加到UIView的问题
- (IBAction)setTimeButtonPressed:(UIButton *)sender
{
// Creates Frame Rects for views and controls
CGRect datePickerViewOutFrame = CGRectMake(0, 336, self.view.frame.size.width, 228);
CGRect datePickerOutFrame = CGRectMake(0, 336, self.view.frame.size.width, 162);
// Create View that will slide out
UIView *datePickerView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 0)];
datePickerView.backgroundColor = [UIColor flatCloudsColor];
// Setup DatePicker
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 0)];
datePicker.datePickerMode = UIDatePickerModeTime;
datePicker.date = [NSDate date];
datePicker.hidden = NO;
[self.view addSubview:datePickerView];
[datePickerView addSubview:datePicker]; /* DOES NOT WORK*/
self.datePickerView.clipsToBounds = YES;
// Animate the views sliding out from the bottom
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
datePicker.frame = datePickerOutFrame;
datePickerView.frame = datePickerViewOutFrame;
}
completion:^(BOOL finished){
// Might need later
}];
}
但是,如果我改变,我添加日期选择器的线路,它的工作原理,但然后我不能把它夹到datePickerView的边界。
[self.view addSubview:datePickerView];
[self.view addSubview:datePicker]; /* Works but can't clip DatePicker */
我在做什么错?
啊,我知道我错过了一些东西。谢谢,那就是诀窍! –