UIWebview键盘返回键按下ios 7 [英] UIWebview keyboard return key pressed ios 7
本文介绍了UIWebview键盘返回键按下ios 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在点击UIWebview的返回键时找到解决方案!
i尝试了以下链接,但它无效!
i am trying to find out a solution when the return key of UIWebview is clicked ! i tried the following links but it's not working !
当用户在UIWebview上键入并按下返回键时,我想做一些偏移工作!
i want to do some offset work when user is typing on the UIWebview and return key is pressed !
这是我正在使用的代码!
Here is the code i am using !
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* plainContent = @"Edit here.....";
NSString* htmlContentString = [NSString stringWithFormat:
@"<html>"
"<body>"
"<div id=\"content\" contenteditable=\"true\" style=\"font-family: Arial\">"
"%@"
"</div>"
"</body></html>", plainContent];
[_webview loadHTMLString:htmlContentString baseURL:nil];
}
- (BOOL)webView:(UIWebView*)aWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
NSString *theTask = (NSString *)[components objectAtIndex:0];
if([[[request URL] absoluteString] rangeOfString:@"enterClicked"].location!=NSNotFound) // When "enterClicked" found
{
NSLog(@"enterClicked !");
//Do your desired work
return NO;
}
if([theTask isEqualToString:@"returnkeypressed"]){
NSLog(@"theTask");
[aWebView endEditing:YES];
return NO;
}
return YES;
}
推荐答案
为什么答案 UIWebView,自定义返回键不起作用?
我试试并为我工作,我只将方法 shouldStartLoadWithRequest:
更改为:
I try that and work for me, I only change the method shouldStartLoadWithRequest:
to:
- (BOOL)webView:(UIWebView*)aWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
NSString *theTask = (NSString *)[components objectAtIndex:0];
if([theTask isEqualToString:@"returnkeypressed"]){
[aWebView endEditing:YES];
return NO;
}
return YES;
}
另一种方法是使用缓冲区文本视图,例如我的 answerwer。
Another way is using a buffer text view, like my answer for change the keyboard.
编辑:您需要添加脚本来检测返回键:
you need add the script to detect the return key:
NSString* plainContent = @"Edit here.....";
NSString* htmlContentString = [NSString stringWithFormat:
@"<html>"
"<head>"
"<script>"
"function returnKeyPressed(event){"
"if(window.event.keyCode == 13)"
"document.location = \"returnkeypressed:\";"
"return true;"
"}"
"</script>"
"</head>"
"<body onKeyPress=\"return returnKeyPressed(event)\">"
"<div id=\"content\" contenteditable=\"true\" style=\"font-family: Arial\">%@"
"</div>"
"</body>"
"</html>",
plainContent];
这篇关于UIWebview键盘返回键按下ios 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文