我的项目包中的 UIWebView 显示了一个 html 文件。我想在 UIWebView 中编辑输入时隐藏 ios 键盘并显示我自己的虚拟键盘(用 Jquery 编写)。在 UIWebView 中编辑内容时是否可以隐藏键盘?我不能对元素使用 blur() 方法,因为我想编辑内容。我需要在没有 iOS 键盘的情况下执行此操作吗?
解决方案
我找到了解决方案。
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
self.webView.delegate=self;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
[super viewDidLoad];
}
- (void)esconde {
for (UIWindow *keyboardWindow in [[UIApplication sharedApplication]
windows])
for (UIView *keyboard in [keyboardWindow subviews])
if([[keyboard description] hasPrefix:@"<UIPeripheralHostView"]
== YES) [keyboard removeFromSuperview];
}
- (void)keyboardWillShow:(NSNotification *)aNotification {
[self performSelector:@selector(esconde) withObject:nil afterDelay:0];
}
最佳答案
解决方案
我找到了解决方案。
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
self.webView.delegate=self;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
[super viewDidLoad];
}
- (void)esconde {
for (UIWindow *keyboardWindow in [[UIApplication sharedApplication]
windows])
for (UIView *keyboard in [keyboardWindow subviews])
if([[keyboard description] hasPrefix:@"<UIPeripheralHostView"]
== YES) [keyboard removeFromSuperview];
}
- (void)keyboardWillShow:(NSNotification *)aNotification {
[self performSelector:@selector(esconde) withObject:nil afterDelay:0];
}
关于iphone - 在编辑内容 UIWebView 时隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18091427/