当禁用键盘
问题描述:
当用户点击UITextField
我显示一个UIDatePicker
输入下面的代码。但是,当我这样做datepicker和正常的文本键盘同时显示。我将如何禁用键盘显示?当禁用键盘
- (IBAction)selectDateBegin:(id)sender {
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 action:@selector(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 action:@selector(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 action:@selector(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];}
答
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
[self.textFieldName resignFirstResponder];
//
// Code ...continue,......for display DatePicker
//
}
答
为您的日期选择一个单独的UIView(具有确定的导航栏和取消按钮)容器中,然后将其分配给textfield.inputView财产。欲了解更多详情,请参阅UITextField Class Reference。
这将加载您的日期选择器视图,而不是默认键盘。
你可以在网上找到更多相同的例子。
希望这是你在找什么。
请检查[this](http://*.com/a/6075062/662096)链接以使用textfield显示选取器视图 – iNeal 2013-03-09 15:22:50