29,028
社区成员
发帖
与我相关
我的任务
分享
- (void)viewDidLoad {
[super viewDidLoad];
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
webView.delegate = self;
[self.view addSubview:webView];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
NSURL *url = [[NSURL alloc] initWithString:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[self.view addSubview:[CIBSafeKeyboardTextField sharedTextField]];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *absolutePath = request.URL.absoluteString;
NSString *scheme = @"rrcc://";
if ([absolutePath hasPrefix:scheme]) {
NSString *subPath = [absolutePath substringFromIndex:scheme.length];
NSString *methodName = [subPath stringByReplacingOccurrencesOfString:@"_" withString:@":"];
SEL sel = NSSelectorFromString(methodName);
if ([self respondsToSelector:sel]) {
[self performSelector:sel];
return NO;
}
}
return YES;
}
- (void)shareToTest {
[[CIBSafeKeyboardTextField sharedTextField] becomeFirstResponder];
}
@interface CIBSafeKeyboardTextField : UITextField
+ (CIBSafeKeyboardTextField *)sharedTextField;
@end
@implementation CIBSafeKeyboardTextField
+ (CIBSafeKeyboardTextField *)sharedTextField {
static CIBSafeKeyboardTextField *_textField = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_textField = [[self alloc] init];
});
return _textField;
}
- (instancetype)init
{
self = [super init];
if (self) {
self.inputView = [[UIView alloc] init];
}
return self;
}
@end
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.btn{height:40px; width:60%; padding: 0px 30px; background-color: #0071E7; border: solid 1px #0071E7; border-radius:5px; font-size: 1.2em; color: white}
</style>
<script>
function myFunction() {
location.href = "rrcc://shareToTest";
}
</script>
</head>
<body>
<select name="hehe" id="">
<option value="1">hehe</option>
<option value="2">hehe</option>
<option value="3">hehe</option>
<option value="4">hehe</option>
<option value="5">hehe</option>
</select>
<button class="btn" type="button" onclick="myFunction()">键盘</button>
</body>
</html>