iOS 7 input elements moving fixed positioned elements
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
Related videos on Youtube
Francesco
Updated on July 10, 2020Comments
-
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 over 10 yearsGlad to help! Feel free to accept the answer so others can see :)
-
Kevin Zych over 10 yearsHave 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 over 10 yearsMy app rotates to landscape when turned and I haven't seen this issue. If I see it I'll let you know.
-
Francesco over 10 yearsI 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 over 10 yearsFooling 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 about 10 yearsI 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 about 10 years<3 Works amazing for me on iOS7, thank you so much... This has solved years trouble lol...
-
nicolas about 10 yearsTried 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 almost 10 yearsDid 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 over 9 yearsForcing 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 over 9 yearsThis is not an answer, but merely an observation; thus belonging as a note instead.
-
Pedro Gabriel over 9 yearsSaved mine too. Amazing how I never would fix it using a meta tag.
-
Dominique Alexandre almost 9 yearsThis 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);