6

I am creating an iPad app using Phonegap. The app has a fixed landscape orientation and a menu running along the top, with a text box inside it on the top right. The app is a fixed (full screen) size and does not require scrolling.

When the user touches the text box that appears top right on iOS 6, the whole app slides left in order to place the text box in the centre of the screen, pushing the whole app left and leaving a blank space on the right.

How do I prevent this behaviour?

I currently have UIWebViewBounce set to NO and the following code in place to catch touchstart events:

document.body.addEventListener('touchmove', function(e) {
    e.preventDefault();
}, false);

I also have this on the text box itself, which seems to work on iOS 5 (albeit with a stutter) but not on iOS 6:

$('#searchText').on("focus", function(event) {
    window.scrollTo(0, 0);
});

Any help greatly appreciated.

colin
  • 393
  • 1
  • 3
  • 8
  • 2023 solution here: https://stackoverflow.com/a/76731361/480608. However, it may need to be adjusted to find the horizontal center rather than the vertical center since your app is in fixed landscape mode. – Raine Revere Jul 20 '23 at 15:31

2 Answers2

3

Try adding this javascript in an onfocus attribute in the input that you don't want to shift when being focused:

<input onfocus="this.style.webkitTransform = 'translate3d(0px,-10000px,0)'; webkitRequestAnimationFrame(function() { this.style.webkitTransform = ''; }.bind(this))"/>
131
  • 1,363
  • 1
  • 12
  • 32
-1

Try to add the following css styles to your body elemnt:

-webkit-touch-callout: none; 
-webkit-user-select: none; 
-khtml-user-select: none; 
-moz-user-select: none; 
-ms-user-select: none;
 user-select: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);

It prevents user selection on links and other stuff. Maybe it will be helfull for you.

kreig
  • 990
  • 11
  • 18