UIWebView horizontal bounce not working

心已入冬 提交于 2019-12-13 16:35:52

问题


I am trying to get my UIWebView to bounce Horizontally, it already bounces vertically but its just not doing the Horizontal bounce.

I add the UIWebView like this

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

Then inside lpViewController viewDidLoad method I have tried to get the horizontal bounce like this.

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;

but thats not working either, it gets the Vertical bounce but not the Horizontal...

any help would be greatly appreciated.


回答1:


To get your UIWebView to bounce both horizontally and vertically, set the bounces property of the scrollview to YES.

Change your code above to:

lockPositionsWebView.scrollView.bounces = YES;

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

The bounces property must be YES for alwaysBounceVertical and alwaysBounceHorizontal to work.

See Apple's doco for alwaysBounceHorizontal:

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.



来源:https://stackoverflow.com/questions/17354895/uiwebview-horizontal-bounce-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!