如何关闭UIWebView水平弹跳

发布于 2024-11-06 18:18:43 字数 509 浏览 3 评论 0原文

简单的问题,我有一个 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;            
    }
}

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;            
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还给你自由 2024-11-13 18:18:43

下面的代码让我们停止弹跳:

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"]];

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

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.

不知在何时 2024-11-13 18:18:43

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

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

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文