iOS 7 input elements moving fixed positioned elements
Asked Answered
N

4

20

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?

Nidify answered 24/9, 2013 at 0:4 Comment(0)
D
44

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" />
Dagoba answered 25/9, 2013 at 14:38 Comment(10)
Glad to help! Feel free to accept the answer so others can see :)Dagoba
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.Gerigerianna
My app rotates to landscape when turned and I haven't seen this issue. If I see it I'll let you know.Dagoba
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.Nidify
We had a similar problem with top absolute positioned elements and In our case an acceptable solution was to put height to 768 in the meta tag.Cambric
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?Bellbella
<3 Works amazing for me on iOS7, thank you so much... This has solved years trouble lol...Flowing
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 valueGrandfather
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.Trodden
Saved mine too. Amazing how I never would fix it using a meta tag.Est
R
8

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);
});
Riba answered 10/7, 2014 at 7:27 Comment(2)
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-4323Duodecillion
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);Unceremonious
M
6

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

Mussel answered 3/10, 2013 at 12:50 Comment(0)
B
-1

Opposum, your solution worked for me but only when the scale was set to 1.0. If I set it to 0.9 then it would be like it was before your suggested fix. I set initial-scale, maximum-scale, and minimum-scale to 0.9 and the bouncing effect of the fixed objects when the keyboard appeared was still happening.

Batho answered 11/10, 2013 at 15:9 Comment(2)
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.Batho
This is not an answer, but merely an observation; thus belonging as a note instead.Jetliner

© 2022 - 2024 — McMap. All rights reserved.