问题
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