如何关闭UIWebView水平反弹

Dan*_*n F 5 zoom objective-c uiwebview bounce ios

简单的问题,我有一个webview,它应该只包含一个图像供用户放大和缩小.为了保持我的外观干净,我想完全禁用此视图上的弹跳,但仍允许滚动.此解决方案适用于垂直反弹,但只要我将图像缩放到大于屏幕的尺寸,水平反弹仍然可能:

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;            
    }
}
Run Code Online (Sandbox Code Playgroud)

Uda*_*ala 11

以下代码为我们停止弹跳提供了诀窍:

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"]];
Run Code Online (Sandbox Code Playgroud)

我不确定这是否会禁用图像缩放.但它应该停止弹跳.


Ale*_*ciu 7

在iOS 5上,您可以通过以下方式解决问题:

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

webView.scrollView.scrollEnabled = NO; 
webView.scrollView.bounces = NO;
Run Code Online (Sandbox Code Playgroud)

注意:这仅适用于iOS5及更高版本