OStack程序员社区-中国程序员成长平台

标题: ios - UIWebView 水平反弹不起作用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 02:56
标题: ios - UIWebView 水平反弹不起作用

我试图让我的 UIWebView 水平反弹,它已经垂直反弹,但它只是不做水平反弹。

我这样添加 UIWebView

// pass data off to the correct view to be used
    lpViewController = [[LPViewController alloc] init];
    lpViewController.view.frame = CGRectMake(0.0, infoBarHeight, lpViewController.view.bounds.size.width, lpViewController.view.bounds.size.height);

    lpViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    lpViewController.view.backgroundColor = [UIColor whiteColor];


    [self.view insertSubview:lpViewController.view belowSubview:actionTabBar];

然后在 lpViewController viewDidLoad 方法中,我尝试像这样获得水平反弹。

for (UIView *subview in [lockPositionsWebView subviews]) {
    if ([subview isMemberOfClass:[UIScrollView class]]) {
        [(UIScrollView *)subview setAlwaysBounceVertical:YES];
        [(UIScrollView *)subview setAlwaysBounceHorizontal:YES];
    }
}

lockPositionsWebView.scrollView.bounces = NO;

lockPositionsWebView.scrollView.alwaysBounceVertical = YES;
lockPositionsWebView.scrollView.alwaysBounceHorizontal = YES;

但这也不起作用,它得到垂直反弹而不是水平反弹......

任何帮助将不胜感激。



Best Answer-推荐答案


要让您的 UIWebView 水平和垂直反弹,请将 ScrollView 的 bounces 属性设置为 YES

将上面的代码更改为:

lockPositionsWebView.scrollView.bounces = YES;

lockPositionsWebView.scrollView.alwaysBounceVertical = YES;
lockPositionsWebView.scrollView.alwaysBounceHorizontal = YES;

bounces 属性必须为 YESalwaysBounceVerticalalwaysBounceHorizo​​ntal 才能工作。

请参阅 Apple 的 alwaysBounceHorizo​​ntal 文档:

A Boolean value that determines whether bouncing always occurs when horizontal scrolling reaches the end of the content view.
If this property is set to YES and bounces is YES, horizontal dragging is allowed even if the content is smaller than the bounds of the scroll view. The default value is NO.

关于ios - UIWebView 水平反弹不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17354895/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4