gpt4 book ai didi

ios - UIWebview 键盘返回键按下 ios 7

转载 作者:行者123 更新时间:2023-11-28 17:54:03 24 4
gpt4 key购买 nike

我正在尝试找到单击 UIWebview 返回键时的解决方案!我尝试了以下链接,但它不起作用!

UIWebView, customize "return" key

How to detect keyboard enter key?

当用户在 UIWebview 上输入并按下返回键时,我想做一些偏移工作!

这是我正在使用的代码!

- (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, customize "return" key没用?

我尝试这样做并为我工作,我只将方法 shouldStartLoadWithRequest: 更改为:

- (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;
}

另一种方法是使用缓冲区 TextView ,就像我的 answer用于更改键盘。

编辑:您需要添加脚本来检测返回键:

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];

关于ios - UIWebview 键盘返回键按下 ios 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20321110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com