I had the following code that sets the contentInset for UIWebView’s scrollView
webScrollView.contentInset = UIEdgeInsetsMake(44, 0.0, 0.0, 0.0);
and here’s how I get the UIWebView scrollView:
- (UIScrollView *)defaultScrollView {
UIScrollView *scrollView = nil;
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:@"5.0" options:NSNumericSearch] != NSOrderedAscending) {
return self.scrollView;
}
else {
for (UIView *subview in [self subviews]) {
if ([subview isKindOfClass:[UIScrollView class]]) {
scrollView = (UIScrollView *)subview;
}
}
if (scrollView == nil) {
NSLog(@"Couldn’t get default scrollview!");
}
}
return scrollView;
}
In iOS 5 calling the above also sets the contentOffset, I know this because it calls the scrollViewDidScroll delegate, however in iOS 4, it doesn’t… any idea why this is and how to fix it?
OK I tested it in the simulator in iOS 4 AND iOS 5. As soon as I set the insets, the delegate gets called in both OS versions.
The documentation of the delegate tells us:
First it says when the user scrolls, which isn’t the case. But in detail it says change in content offset, which happens, when you set an inset. Because the content won’t change in position, when you set a contentinset, so it corrects the offset correspondingly.
So it’s not a bug. But the delegate should be called. In my test – it did.
OK my complete test: The only difference between 4.0 and 5.0, that I see, is that the ScrollView is a
_UIWebViewScrollViewin 5.0. Also the webview-scrollview behaves different from a standard-scrollview. In a standard scrollView the delegate GETS called, in the webviewScrollView it GETS NOT called.Complete test code:
Resulting Log for iOS 4.0:
Resulting Log for iOS 5.0: