How to prevent keyboard push up webview at iOS app using phonegap

前端 未结 6 489
无人及你
无人及你 2020-11-30 01:16

When an input field at bottom of the screen has focus, the keyboard pushes up my webview and the upper part of the page is not visible anymore.

I want to prevent the

6条回答
  •  情书的邮戳
    2020-11-30 02:00

    Solved this issue using driftyco/ionic-plugins-keyboard (https://github.com/driftyco/ionic-plugins-keyboard)

    First install keyboard plugin:

    cordova plugin add com.ionic.keyboard
    

    Now you can I) either disable native keyboard scrolling:

    cordova.plugins.Keyboard.disableScroll(true);
    

    or II) listen on native.keyboardshow event in deviceready and scroll back to top when keyboard shows:

    window.addEventListener('native.keyboardshow', keyboardShowHandler);
    
    function keyboardShowHandler(e){
        setTimeout(function() {
            $('html, body').animate({ scrollTop: 0 }, 1000);
        }, 0);
    }
    

    I used the II) approach because I liked the animated scrolling in my case. If you don't want to go with the animation replace the corresponding line with window.scrollTo(0, 0);. But I'm afraid that in that case you will again have to deal with this "litter jitter animation" Imskull wrote about.

提交回复
热议问题