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;
((UIScrol开发者_如何学GolView*) subview).alwaysBounceHorizontal = NO;
((UIScrollView*) subview).bouncesZoom = NO;
}
}
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.
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
精彩评论