UIWebView under transparent UINavigationBar

I have a UIWebView that I want to put under my translucent UINavigationBar. Usually, when I put a UIScrollView under a translucent UINavigationBar, I set its contentOffset so that all the content will be popped out first after the bar so that it can be seen; after that, the user can scroll the text, and he will overlap the panel.

The problem is that UIWebView is not a proper subclass of UIScrollView; this way i cant use setContentOffset. Does anyone have tips or tricks for getting a UIWebView to look good with a transparent navigation bar? Thanks.

+6
objective-c iphone cocoa-touch
source share
6 answers

I am not sure if there is a clean method for this. I have not tried, but here is the idea:

  • draw uiwebview at the origin 0,0
  • intercept all touch screen
  • if you find that the user is dragging and dropping (scrolling the webview), don't miss the touch
  • Instead, move the webview up x pixels so that its start is (0, -x). Then change the height to add x pixels
  • You will need to save some state so that you know when to stop resizing the web view and start passing strokes to scroll through the web view.

Returning is the same as doing it when you drag it down (scroll through the webview).

0
source share

As in iOS 5, you can use the scrollView property of UIWebView and set the contentInset parameter to 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); 
+9
source share

The easiest way is to install:

 webView.clipsToBounds = NO; webView.scrollView.clipsToBounds = NO; 

It works on bout iOS 7 and 6, and I haven't tried it, but on iOS 5 probably also

+3
source share

I achieved this by setting a subspecies of the UIWebView so as not to crop the borders, then I could put a toolbar on top of it and get the desired effect:

 for (UIView *subview in theWebView.subviews) { subview.clipsToBounds = NO; } 
+2
source share

Another way to do this is to insert the div into the html code you are viewing so that it is located at the top of the page. make sure you set the scaling correctly and set the start of uiwebview (0, -x) to start.

0
source share

With the advent of iOS 7, the offset height should now include the height of the top status area. Otherwise, iOS7 devices will have 20 pixels web browsing that are still hidden under the navigation bar.

In a project that should support iOS 7 and older devices, a macro similar to that found here:

 #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) 

It can be very helpful. The modified version of the zerotool utility code above can 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.) 
0
source share

All Articles