在应用委托窗口中添加了subview
,textfield
位于subview
,startDateTxtFld
将打开日期选择器,但日期选择器仍在键盘后面。键盘不会隐藏在resignFirstResponder
或self.view
eneEditing
设置为true
。
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == startDateTxtFld )
{
startDateSelected =YES;
endDateSelected = NO;
// [referenceNmbrTxtFld resignFirstResponder];
// [startDateTxtFld becomeFirstResponder];
//textField.inputView=datePicker;
// [self.view endEditing:YES];
// [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
// [APP_DELEGATE.window resignFirstResponder];
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
[UIView animateWithDuration:0.5 animations:^
{
[startDateTxtFld resignFirstResponder];
_bottomGap4DatePicker.constant=0;
datePicker.backgroundColor=[UIColor whiteColor];
// [_subVw4DtPkr becomeFirstResponder];
}];
[self.navigationController.view endEditing:YES];
}
else if (textField == endDateTxtFld)
{
startDateSelected =NO;
endDateSelected = YES;
// [self.view endEditing:YES];
// [referenceNmbrTxtFld resignFirstResponder];
// [endDateTxtFld becomeFirstResponder];
// textField.inputView=datePicker;
// [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
// [APP_DELEGATE.window resignFirstResponder];
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
[UIView animateWithDuration:0.5 animations:^
{
// [endDateTxtFld resignFirstResponder];
_bottomGap4DatePicker.constant=0;
datePicker.backgroundColor=[UIColor whiteColor];
//[_subVw4DtPkr becomeFirstResponder];
}];
[self.navigationController.view endEditing:YES];
}
else
{
[textField becomeFirstResponder];
_bottomGap4DatePicker.constant=[UIScreen mainScreen].bounds.size.height +_subVw4DtPkr.frame.size.height;
_popUpVwConstraint.constant=-30;
}
}
答案 0 :(得分:0)
(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { {
NSLog(@"textFieldDidBeginEditing===%@" , textField.text);
CGAffineTransform translation = CGAffineTransformIdentity;
if (textField==vacDate || textField==vacTime) {
[self.view endEditing:YES];
[UIView beginAnimations:nil context:nil];
self.view.transform = translation;
[UIView commitAnimations];
myDatePicker.hidden = NO;
return NO;
}
else
{
if (textField==vacType) {
translation = CGAffineTransformMakeTranslation(0, -60);
}
[UIView beginAnimations:nil context:nil];
self.view.transform = translation;
[UIView commitAnimations];
myDatePicker.hidden = YES;
return YES;
}
}
答案 1 :(得分:0)
隐藏IOS中的键盘:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView * txt in self.view.subviews){
if ([txt isKindOfClass:[UITextField class]] && [txt isFirstResponder]) {
[txt resignFirstResponder];
}
}
}
OR
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
答案 2 :(得分:0)
我尝试了所有解决方案,例如添加
UITextFieldDelegate
tf_edit.returnKeyType = UIReturnKeyDone
- (BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}
没有任何帮助。
正在调用textFieldShouldReturn。但键盘没有出现。当我点击DONE按钮时,我看到它会转到其他文本字段。但是没有其他文本领域。因此,我没有将resignFirstResponder应用于我的文本域名,而是应用于textfield,它是textFieldShouldReturn函数的一个参数,并且它有效。我不确定这是否正确。它对我有用。
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
//[tf_edit resignFirstResponder];
[textField resignFirstResponder];
return YES;
}