Phonegap: Keyboard changes window height in iOS 7

前端 未结 9 596
一整个雨季
一整个雨季 2020-12-14 21:48

In iOS 6 everything works fine. The keyboard opens and moves the input into view. When the keyboard closes everything goes back where it should.

In iOS 7 the keyboar

9条回答
  •  臣服心动
    2020-12-14 22:20

    After I upgraded my project to iOS with cordova 3.1 I start having similar problems for the input fields in where I did not have the code listed above. The keyboard pushes things up and the header and footer did not returned to their original positions. I have tested and that solve the problem (maybe not very elegantly but it is a workaround). I just put that code on my pageinit event.

     /************************************************************************************************* 
     * FIX: to avoid the buggy header and footer to jump and stick not
     * to the top/bottom of the page after an input or textfield lost focus and the keyboard dissapear                          *
     *************************************************************************************************/ 
     $('input, textarea')
     .on('focus', function (e) {
        $('header, footer').css('position', 'absolute');
     })
     .on('blur', function (e) {
        $('header, footer').css('position', 'fixed');
        //force page redraw to fix incorrectly positioned fixed elements
        setTimeout( function() {
            window.scrollTo( $.mobile.window.scrollLeft(), $.mobile.window.scrollTop() );
        }, 20 );
     });
    

提交回复
热议问题