移动设备上的键盘输入重叠

时间:2017-04-14 15:45:27

标签: android cordova meteor mobile angular-meteor

我正在开发一个带角度流星的应用程序,每当我对焦在屏幕底部的输入时,键盘就会重叠。

我尝试将其添加到我的mobile-config.js但不起作用:

App.setPreference('fullscreen', false);
App.setPreference('android-windowSoftInputMode', 'adjustResize');

还有我的index.html上的这个元数据:

<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, target-densitydpi=device-dpi, width=device-width" />

我忘记了什么吗?

2 个答案:

答案 0 :(得分:1)

所以你有两个选择Android(iOS处理它对你来说更好)。在AndroidManifest.xml文件中,您会在第一个android:windowSoftInputMode标记内看到<activity>。这将调整键盘与屏幕交互的方式。 Here是有关其工作原理的更多信息。

答案 1 :(得分:1)

这几乎适用于所有情况。

此代码位于以下路径:

── client
   ├── main.js

// Global variables 
let keyboardHeight = 0, originalHeight = 0;

Meteor.startup(() => {
    if(Meteor.isCordova){
        StatusBar.hide();

        // ionic plugin defaults to hide it
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false);

        // Android specific events
        isAndroid = cordova.platformId == 'android';
        if(isAndroid){
            // Handle android backbutton
            document.addEventListener("backbutton", onBackButtonDown, false);

            // Using ionic-plugin-keyboard
            window.addEventListener("native.keyboardshow", onShowKeyboard, false);
            window.addEventListener("native.keyboardhide", onHideKeyboard, false);
        }
    }
};
onShowKeyboard = function(e){
    let elem = document.activeElement,      // Get the focused element
        $parent = $(elem).scrollParent();   // Get closest scrollable ancestor (jQuery UI)

    // If there is no scrollable parent, no need to continue processing
    if($parent.length == 0){
        return;
    }

    // Check if the keyborad type has changed (i.e. from text to number)
    if(keyboardHeight != e.keyboardHeight){
        keyboardHeight = e.keyboardHeight;
    }

    // Don't resize if the original height hasn't been reset by onHideKeyboard()
    if(originalHeight == 0){
        originalHeight = $parent.height();
    }

    // Subtract keyboard height from parent height + accessory bar height
    // Add some class to the parent, to be able to get it back to normal state onHideKeyboard()
    $parent.height(originalHeight - keyboardHeight + 50).addClass('adjusted');

    // Give the keyboard time to show
    setTimeout(function() {     
        // Scroll to active element
        document.activeElement.scrollIntoView({
            behavior: "smooth", // or "auto" or "instant"
            block: "center"     // or "start" or "end"
        });
    }, 100);

    // Unbind DOM object from HTML for garbage collection
    elem = null;
    $parent.prevObject = null; // To avoid memory leak (for any jQuery DOM object)
    $parent = null;
};
onHideKeyboard = function(e){
    let s = $('.adjusted').attr('style');
    s = s.replace(/height.*;/, '');
    $('.adjusted').attr('style', s).removeClass('adjusted');
    keyboardHeight = 0;
    originalHeight = 0;
};