Fix the Web View shrink issue in iOS7 using PhoneGap

Problem:
I received a bug ticket from my client about the unusual behavior of my application UI. It was a problem which was occurring only in iOS7 only.
When the keyboard pops up in iPad devices running on iOS7 the web view of our app gets shrink (app development using Phonegap).

Solution that works for me :
This problem can be solved in few steps.

  1. We need to go to Config.xml and inside the preference tag just need to set the value of KeyboardShrinksView to false.
  2. And do not add height = device-height inside the meta tag for viewport. <meta name=”viewport” content=”user-scalable=no, width=device-width, initial-scale = 1.0, maximum-scale = 1.0″>
  3. Now we may have the media queries in CSS file for different orientation (i.e portrait or landscape).
  4. Now we have to add the height to viewport dynamically. Now lets see the code.

We need to call this function on document ready.

function getHeight(){    
		//Setting the height to null.
               var customContent = 'user-scalable=no, initial-scale=1, maximum-scale=1, 						width=device-width, height ='+ "";
		//setting the attribute to viewport.
                $('meta[name = "viewport"]').attr('content',customContent);
             window.setTimeout(function(){
                //Timeout to set the height.
               var ChangeHeight = $(window).height();
                var customContent = 'user-scalable=no, initial-scale=1, maximum-scale=1, 						width=device-width, height ='+ ChangeHeight;
		// Setting the Original height.
                $('meta[name = "viewport"]').attr('content',customContent);
             },300);
    }
	// On orientation change calling getHeight() function.
    window.addEventListener("orientationchange",function(){getHeight();});
});

Hope this will help!!.

Written By: Anuj Dubey, Software Developer, Mindfire Solutions

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s