Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable UIWebview horizontal scrolling?

I've tried disabling it by inserting:

<meta name="viewport" content="width=320" />

into my HTML string, and a dozen variations of the above in the vain hope that I just screwed up the tag syntax... but nothing seems to stop UIWebView from scrolling horizontally. And yet there are apps that manage to do this (like MobileRSS), and presumably, since they haven't gotten rejected, they're not using private APIs.

like image 270
akaii Avatar asked Mar 07 '10 19:03

akaii


People also ask

How do I turn off horizontal scrolling?

To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML. CSS.

How do I stop horizontal scrolling in web design?

You can also set the overflow-x CSS property to hidden, which prevents child content from wrapping within its container but turns off sideways scrolling. Another solution is to set the width of child elements to 100%.


3 Answers

My version, a common solution:

- (void)webViewDidFinishLoad:(UIWebView *)webView {

[webView.scrollView setContentSize: CGSizeMake(webView.frame.size.width, webView.scrollView.contentSize.height)];

}
like image 140
Denis Kutlubaev Avatar answered Oct 10 '22 22:10

Denis Kutlubaev


I eventually managed to solve this. I'd already tried setting the viewport width value, and it didn't work. What DID work was using overflow:hidden in conjunction with setting the viewport width. Thanks for answering anyhow.

like image 8
akaii Avatar answered Oct 11 '22 00:10

akaii


Your web page needs to have two attributes: 1 -- the viewport meta tag and 2-- a width of 320px or less, including margin and padding.

Here's a very bare HTML5 skeleton that should allow vertical scrolling and disallow horizontal scrolling, including disallowing horizontal bouncing. This also disallows zooming -- it assumes that your web page should always be shown 1-1 to the user. This is useful if you're using an UIWebView to show a user interface.

<!doctype html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0" />
    <style>
        body {width:320px;margin:0;padding:0;}
    </style>
</head>
<body></body>
</html>
like image 4
Vineel Shah Avatar answered Oct 10 '22 23:10

Vineel Shah