iOS 8 jquery mobile 1.4.4输入键盘不再隐藏页脚菜单了

时间:2014-10-09 13:32:16

标签: jquery-mobile cordova-3

iOS 8 jquery mobile 1.4 cordova 3.6.3任何模拟器,任何物理真实设备

问题是当键盘出现在表单字段中输入时隐藏页脚

previous solution在iOS7上表现不错,现在点击输入元素看起来不错,但是如果你滚动表单,页脚会出现(固定在页面上)与其他输入字段重叠。

1 个答案:

答案 0 :(得分:0)

找到解决方案!

的iOS

必须编辑org.apache.cordova.dialogs插件的src文件夹中的CDVNotification.m和CDVNotification.h,如下所述:add properties and methods to CDVnotification

由于不清楚在哪里放置新行,这是CDVnotification.h中的新代码

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioServices.h>
#import <Cordova/CDVPlugin.h>

@interface CDVNotification : CDVPlugin <UIAlertViewDelegate>{}

@property (strong) NSString* keyboardShowcallbackId;
@property (strong) NSString* keyboardHidecallbackId;

- (void)alert:(CDVInvokedUrlCommand*)command;
- (void)confirm:(CDVInvokedUrlCommand*)command;
- (void)prompt:(CDVInvokedUrlCommand*)command;
- (void)beep:(CDVInvokedUrlCommand*)command;

- (void)keyboardShow:(CDVInvokedUrlCommand*)command;
- (void)keyboardHide:(CDVInvokedUrlCommand*)command;

@end

@interface CDVAlertView : UIAlertView {}
@property (nonatomic, copy) NSString* callbackId;

@end

然后在这里我粘贴CDVNotification.m中的新行

- (void)beep:(CDVInvokedUrlCommand*)command
{
    NSNumber* count = [command.arguments objectAtIndex:0 withDefault:[NSNumber numberWithInt:1]];
    playBeep([count intValue]);
}

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

@end

@implementation CDVAlertView

@synthesize callbackId;

@end

然后在cordova / phonegap应用程序中查找ondeviceready事件的位置并粘贴两个cordova.exec行。

onDeviceReady: function() {
    app.receivedEvent('deviceready');

    navigator.splashscreen.hide();

}, // fine onDeviceReady

receivedEvent: function(id) {

   console.log('Received Event: ' + id);

    if (isMobile.iOS()) {

        alert("this is iOS"); //

        cordova.exec(function(){  $("#footer").hide();  },function(){console.log("error");},"Notification","keyboardShow",[]);

        cordova.exec(function(){  $("#footer").show();  },function(){console.log("error");},"Notification","keyboardHide",[]);

    } else { 

        alert("this is android"); 

        document.addEventListener("showkeyboard", function(){ $("#footer").hide(); }, false);
        document.addEventListener("hidekeyboard", function(){ $("#footer").show(); }, false);


    }



}

的Android

以前的解决方案,当css虚拟键盘出现时检测窗口调整大小的js插入代码仍在Android中工作

<script type="text/javascript">
document.write( '<style>#footer{visibility:hidden}@media(min-height:' + ($( window ).height() - 10) + 'px){#footer{visibility:visible}}</style>' );
</script> 

然而我选择了

document.addEventListener("showkeyboard", function(){ $("#footer").hide(); }, false);
document.addEventListener("hidekeyboard", function(){ $("#footer").show(); }, false);

如果是Android设备。

希望能帮助像我这样的人在一个月后挣扎这个:) !!