iOS 7 input elements moving fixed positioned elements

23,420

Solution 1

This fixed the problem for my cordova app. I'm not sure if it applies to you but just in case.

Check your html meta tags for something like this:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">

Replace it with this:

<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi" />

Solution 2

In our case this would fix itself as soon as user scrolls. So this is the fix we've been using to simulate a scroll on blur on any input or textarea:

$(document).on('blur', 'input, textarea', function () {
    setTimeout(function () {
        window.scrollTo(document.body.scrollLeft, document.body.scrollTop);
    }, 0);
});

Solution 3

I ran across exactly the same problem & gave up after two days of experimenting. It seems that: a) all bottom-fixed elements go upwards so that their bottom offset is relative to the top edge of the keyboard c) all top-fixed elements stay in their original position (do not move upwards as they used to) - note that top-absolute elements work ok.

The only solution I found was to have a custom iPad stylesheet that replaces all fixed elements with absolute elements, sets the css bottom property to auto and uses top instead

Share:
23,420

Related videos on Youtube

Francesco
Author by

Francesco

Updated on July 10, 2020

Comments

  • Francesco
    Francesco over 3 years

    I'm trying to recompile an app for iOS 7, since nothing of the old one works so far. One of the many problems is that I'm using some inputs inside UIWebViews. Text inputs, pickers etc.

    Now, when the iOS 7 shining white keyboard appears, all the bottom fixed elements in the webpage (such as, confirm buttons) are scrolled upward, as if the 'top' of the virtual keyboard is the new bottom of my UIWebView. This is a substantially different behavior from iOS6.x

    Is there any magic trick to make the virtual keyboard behavior work like it used to, without injecting JS/CSS to the webView?

  • Opossum
    Opossum over 10 years
    Glad to help! Feel free to accept the answer so others can see :)
  • Kevin Zych
    Kevin Zych over 10 years
    Have you tried this with a landscape app? "device-height" when in landscape is still 1024 so the bottom of the screen is out of view.
  • Opossum
    Opossum over 10 years
    My app rotates to landscape when turned and I haven't seen this issue. If I see it I'll let you know.
  • Francesco
    Francesco over 10 years
    I haven't accepted the answer yet because this didn't solve my problem. Actually, it made no difference. My experience was similar to what Pawel describes in the other answer, and as a quick fix I ended up having two different stylesheets as well.
  • David Shears
    David Shears over 10 years
    Fooling around with the meta's content, it seems minimum-scale is the problem. When ignored the position fixed issue exists. When set to a value less than 1.0 the position fixed issue exists. When set to a value greater than or equal to 1.0 the position fixed issue is resolved.
  • Sudheer Kumar Palchuri
    Sudheer Kumar Palchuri about 10 years
    I am also facing the same issue in iOS7 in native app, but not able to fix with above code. I am using url to load on the webview,any help?
  • Ilan Kleiman
    Ilan Kleiman about 10 years
    <3 Works amazing for me on iOS7, thank you so much... This has solved years trouble lol...
  • nicolas
    nicolas about 10 years
    Tried this but did not worked for me The only thing that helped me is changing the fixed elements to absolute and update the top value with the scroll value
  • Moos
    Moos almost 10 years
    Did not work for me. In fact target-densityDpi is no longer supported. I'm getting a "Viewport argument key "target-densitydpi" not recognized and ignored." by the Safari browser.
  • zungaphobia
    zungaphobia over 9 years
    Forcing the scroll like this worked for me. The viewport fix below can work, but can also cause problems with Cordova apps, where width=device-width, height=device-height, can lead to scrolling problems. issues.apache.org/jira/browse/CB-4323
  • SikoSoft
    SikoSoft over 9 years
    This is not an answer, but merely an observation; thus belonging as a note instead.
  • Pedro Gabriel
    Pedro Gabriel over 9 years
    Saved mine too. Amazing how I never would fix it using a meta tag.
  • Dominique Alexandre
    Dominique Alexandre almost 9 years
    This solution seems to be the only one that doesn't break anything. You could also check the user agent to limit this to only mobile devices. var is_mobile = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|‌​(webOS)/i);

Related