我的项目包中的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];
}
答案 0 :(得分:1)
解
我找到了解决方案。
- (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];
}