我知道我必须打电话
- (BOOL)disablesAutomaticKeyboardDismissal {
return NO;
}
//this dismiss keyboard on ios
- (BOOL) textViewShouldBeginEditing:(UITextView *)textView {
[self.comments resignFirstResponder];
return YES;
}
为了关闭表单上的键盘,我也知道我必须调用disablesAutomaticKeyboardDismissal
在导航控制器中(如果我有的话)。
问题是:我以编程方式使用导航控制器创建表单,如下所示:
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
SettingsViewController *settingsVC = [sb instantiateViewControllerWithIdentifier:@"settingsViewController"];
//add navigation controller
UINavigationController *modalViewNavController= [[UINavigationController alloc] initWithRootViewController:settingsVC];
modalViewNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
modalViewNavController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:modalViewNavController animated:YES];
所以我没有表单的导航控制器类,在这种情况下如何关闭键盘?
我必须创建导航视图控制器吗?
更新::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::
最终在故事板中创建一个导航控制器并调用disablesAutomaticKeyboardDismissal
在导航控制器的视图控制器中,这解决了问题,但我仍然想知道如何在不创建导航控制器类的情况下执行此操作。
欢迎任何意见......
您可以尝试以下代码吗?
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
gestureRecognizer.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:gestureRecognizer];
}
- (void)hideKeyboard {
[self.view endEditing:YES];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)