Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off UIWebView horizontal bounce

Simple problem, I have a webview that is supposed to hold just an image for the user to be able to zoom in and out. To keep my look clean, I want to completely disable bouncing on this view, but still allow scrolling. This solution does work for the vertical bounce, but as soon as I zoom the image to a size larger than the screen, horizontal bounce is still possible:

for (id subview in webView.subviews 
{
    if ( [[subview class] isSubclassOfClass:[UIScrollView class]] )
    {

        ((UIScrollView*) subview).bounces = NO;
        ((UIScrollView*) subview).alwaysBounceVertical = NO;
        ((UIScrollView*) subview).alwaysBounceHorizontal = NO;
        ((UIScrollView*) subview).bouncesZoom = NO;            
    }
}
like image 294
Dan F Avatar asked May 13 '11 18:05

Dan F


Video Answer


2 Answers

The following code did the trick for us to stop bouncing:

NSString* scriptToPreventBouncing = @"<script type=\"text/javascript\"> document.ontouchmove = function(e){ e.preventDefault(); } </script>";
NSString* footerHTML = @"<div>All rights reserved</div>";
[footer loadHTMLString: [scriptToPreventBouncing stringByAppendingString:footerHTML] baseURL:[NSURL URLWithString:@"http://somewebsite.com"]];

I am not sure if this will disable the zooming of image. But it should stop the bouncing.

like image 109
Udayakumar Rayala Avatar answered Sep 27 '22 19:09

Udayakumar Rayala


On iOS 5 you can solve your problem this way:

UIWebView *webView = [[UIWebView alloc] ....];

webView.scrollView.scrollEnabled = NO; 
webView.scrollView.bounces = NO;

NOTE: this will work only on iOS5 and higher

like image 39
Alex Stanciu Avatar answered Sep 27 '22 19:09

Alex Stanciu