How to disable horizontal bounce UIWebView

A simple problem, I have a webview that should only contain an image so that the user can zoom in and out. To make my view look clean, I want to completely disable bouncing on this view, but still allow scrolling. This solution really works for vertical bounce, but as soon as I enlarge 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;            
    }
}
+5
source share
2 answers

The following code helped us stop the jump:

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 image scaling. But he must stop jumping.

+11

iOS 5 :

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

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

: iOS5

+7

All Articles