UIWebView水平弹跳不起作用

时间:2013-06-27 23:28:12

标签: ios uiview uiwebview uiscrollview

我试图让我的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;

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

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:4)

要让UIWebView水平和垂直反弹,请将滚动视图的bounces属性设置为YES

将上面的代码更改为:

lockPositionsWebView.scrollView.bounces = YES;

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

bounces YES属性必须alwaysBounceVertical才能alwaysBounceHorizontalalwaysBounceHorizontal工作。

请参阅Apple的doco {{1}}:

  

一个布尔值,用于确定是否始终发生弹跳   水平滚动到达内容视图的末尾   如果此属性设置为YES 并且弹跳为YES ,则水平拖动为   即使内容小于滚动的边界也允许   视图。默认值为NO。