I have a UIWebView which I want to put under my translucent UINavigationBar. Normally when I put a UIScrollView under a translucent UINavigationBar, I set its contentOffset such
I achieved this by setting the UIWebView subviews to not clip to bounds, then I could put a toolbar on top of it and get the desired effect:
for (UIView *subview in theWebView.subviews) {
subview.clipsToBounds = NO;
}
As of iOS 5 you can use the scrollView property of UIWebView, and set a contentInset to adjust the positon.
CGFloat top = 0.0;
if( self.navigationController != nil && self.navigationController.navigationBar.translucent ) {
top = self.navigationController.navigationBar.bounds.size.height;
}
UIWebView* wv = ...
wv.scrollView.contentInset = UIEdgeInsetsMake(top, 0.0, 0.0, 0.0);
The easiest way is to set:
webView.clipsToBounds = NO;
webView.scrollView.clipsToBounds = NO;
It work on bouth iOS 7 & 6, and I didn't try, but on iOS 5 probably too
With the advent of iOS 7, the offset height would now need to include the height of the top status area. Otherwise, iOS7 devices will have 20 pixels of webview still hidden under the navigation bar.
In a project that needs to support iOS 7 and older devices, a macro like the one found here:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
Can be very useful. A modified version of zerotool's helpful code listed above could now look something like this:
if (self.navigationController != nil && self.navigationController.navigationBar.translucent) {
top = self.navigationController.navigationBar.bounds.size.height;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
top += [[UIScreen mainScreen] applicationFrame].origin.y;
}
}
// (etc.)
I am not sure if there is a clean method to doing this. I have not tried it, but here is an idea:
Getting it back is the same only you do it on a drag down (scrolling down the webview).
Another way to possibly do this is to insert a div in the html code you are rendering so that it is spaced out up on the top of the page. make sure you set your zoom correctly and set the uiwebviews origin to (0, -x) to begin with.