问题
Using Xcode 5, iOS 7.
Problems occurs after changing the frame of the web view from (0, 45, 320, 568 - 20 - 45 - 49) to (0, 0, 320, 568 - 20) or change it back, its superview is its container with a frame (0, 20, 320, 548) to the rootViewController of application window.
When changing web view's frame back to (0, 45, 320, 568 - 20 - 45 - 49) to its container, web view is within 65 to (568 - 49) vertical area, but its scroll bar is scrolling from 65 to around middle of the web view.
回答1:
A Solution
Finally I worked it around by give this:
[[[_webViewContainer webView] scrollView] setScrollIndicatorInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
whenever a new web page gets loaded in web view, that is, the very beginning of this UIWebViewDelegate protocol method
-(BOOL)webView:shouldStartLoadWithRequest:navigationType
So even if the auto layout is turned on, we can force the scroll view (the property of web view) give have correct scrolling range for the scroll indicator.
Possible Cause
The reason of the unexpected behavior can be seen by:
UIEdgeInsets tempEdgeInsets;
tempEdgeInsets = [[_webView scrollView] scrollIndicatorInsets];
NSLog(@"scroll view edge insets = %f, %f, %f, %f", tempEdgeInsets.top, tempEdgeInsets.bottom, tempEdgeInsets.left, tempEdgeInsets.right);
Every time the change of web view frame would give a tempEdgeInsets.bottom
to 520
because of the auto layout I guess.
来源:https://stackoverflow.com/questions/19785071/scroll-bar-of-ios-web-view-change-into-half-of-it-should-be