我有一段非常简单的代码,只是为了尝试在软键盘打开时发出警报。我只是想证明这是显示键盘打开的可行方法。
document.addEventListener('deviceready', function () {
$.app.deviceReady();
document.addEventListener("showkeyboard", function(){ alert("Keyboard is ON");}, false);
document.addEventListener("hidekeyboard", function(){ alert("Keyboard is OFF");}, false);
}, false);
这些事件永远不会在 IOS 上触发。仅限安卓。我曾经在 IO7 上看到过一个插件可以帮助解决这个问题,但我现在根本找不到它。
我正在使用 PG 3.1.0PG Build.
Edit:我只是想强调这是为了音隙构建,这意味着据我所知,我无法使用任何自定义插件。仅列出此处:https://build.phonegap.com/plugins https://build.phonegap.com/plugins
我也面临着同样的问题。没有可用的插件。最后我为 iOS 添加了新的插件方法。
在您的应用程序上添加 CDVNotification 插件并添加以下方法和属性。
CDVNotification.h
@property (strong) NSString* keyboardShowcallbackId;
@property (strong) NSString* keyboardHidecallbackId;
- (void)keyboardShow:(CDVInvokedUrlCommand*)command;
- (void)keyboardHide:(CDVInvokedUrlCommand*)command;
CDVNotification.m
//Keyboard notifications.
- (void)keyboardShow:(CDVInvokedUrlCommand*)command {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
self.keyboardShowcallbackId = command.callbackId;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardShowCallback:)
name:UIKeyboardWillShowNotification object:nil];
}
- (void)keyboardHide:(CDVInvokedUrlCommand*)command {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
self.keyboardHidecallbackId = command.callbackId;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardHideCallback:)
name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyBoardHideCallback:(NSNotification*)notification {
if (self.keyboardHidecallbackId) {
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[result setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:result callbackId:self.keyboardHidecallbackId];
}
}
- (void)keyBoardShowCallback:(NSNotification*)notification {
if (self.keyboardShowcallbackId) {
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[result setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:result callbackId:self.keyboardShowcallbackId];
}
}
您可以使用以下代码在打开和隐藏键盘时获取回调。
cordova.exec(function(){alert("Keyboard is ON");},function(){alert("error");},"Notification","keyboardShow",[]);
cordova.exec(function(){alert("keyboard is OFF");},function(){alert("error");},"Notification","keyboardHide",[]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)