我有一个 UITableCell 并且在该单元格上我有一个 UITextBox,当单击文本框而不是显示键盘时,将显示一个 UIDatePicker 并使用下面的代码。但我无法定位 UIDatePicker。我需要它从页面的最底部开始,此时它似乎从按下文本框的表格部分的顶部开始。当用户单击首选日期标签时,代码会触发。任何指针?我附上了一张图片来显示它当前的渲染位置。谢谢。
- (IBAction)selectDateBeginid)sender {
//Disable Keyboard
[self.txtBookingDate resignFirstResponder];
//Disable Scrolling
[_tableForm setScrollEnabled:false];
if ([self.view viewWithTag:9]) {
return;
}
CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height-216-44, 320, 44);
CGRect datePickerTargetFrame = CGRectMake(0, self.view.bounds.size.height-216, 320, 216);
UIView *darkView = [[UIView alloc] initWithFrame:self.view.bounds];
darkView.alpha = 0;
darkView.backgroundColor = [UIColor blackColor];
darkView.tag = 9;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self actionselector(dismissDatePicker] ;
[darkView addGestureRecognizer:tapGesture];
[self.view addSubview:darkView];
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height+44, 320, 216)] ;
datePicker.tag = 10;
[datePicker addTarget:self actionselector(changeDate forControlEvents:UIControlEventValueChanged];
[self.view addSubview:datePicker];
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
toolBar.tag = 11;
toolBar.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self actionselector(dismissDatePicker];
[toolBar setItems:[NSArray arrayWithObjects:spacer, doneButton, nil]];
[self.view addSubview:toolBar];
[UIView beginAnimations"MoveIn" context:nil];
toolBar.frame = toolbarTargetFrame;
datePicker.frame = datePickerTargetFrame;
darkView.alpha = 0.5;
[UIView commitAnimations];
}
我建议你用这个指令替换你的 textField 的 inputView(默认是键盘):
UIDatePicker *datePicker = [[UIDatePicker alloc] init] ;
[datePicker addTarget:self actionselector(changeDate forControlEvents:UIControlEventValueChanged];
[preferredDateField setInputView:datePicker];
更合适且符合 Apple 人机界面指南
关于ios - UIDatePicker 未在 UITable 上正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15310958/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |