So I have been trying to get this simple behavior working on my iPhone app now for a while. I have a nav bar at the top and a tab bar at the bottom. I am loading all of my content in a webview, which I want to fit between the two. I have posted about this issue twice already,
both here: IOS View still does not load in the correct position
and here: Programmatically setting content to fill screen between tab bar and nav controller
Currently, my webview looks and performs fine on iPhone 4 and 4s, the issue arises on the 5s. When the screen finishes loading, it looks like the image here: http://grosh.co/screen.jpg . This occurs on both the simulator as well as devices.
Upon further inspection, I discovered that the UIWebView is in fact spanning correctly (the grey areas you see are the webview). The smaller content is actually a UIWebBrowserView, which I am having a hard time finding any information on.
I have the code I am using below, as well as a log output to insure all the numbers are correct. My questions are,
1) Is there a better way to set the webview to span the screen area between the top and bottom bars for all devices?
2) If not, is there a way to set the UIWebBrowser to span the entire webview?
I tried iterating over the subviews of the webview as described here: http://normansoven.com/ios-webview/#.VHyOUr6Jnww but the webBrowserView was never seen.
Teh Codez:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGFloat viewheight = self.view.bounds.size.height;
NSLog(@"Height1:%f",viewheight);
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat viewheight2 = screenRect.size.height;
NSLog(@"Height2:%f",viewheight2);
CGFloat height = self.view.frame.size.height;
NSLog(@"Height3:%f",height);
CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height;
NSLog(@"NAVHeight:%f",navBarHeight);
CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height;
NSLog(@"TABHeight:%f",tabBarHeight);
CGFloat statusbarheight = [UIApplication sharedApplication].statusBarFrame.size.height;
NSLog(@"StatbarHeight:%f",statusbarheight);
CGFloat spaceToRemove = navBarHeight + tabBarHeight + statusbarheight;
NSLog(@"NAVHeight+TABHeight:%f",spaceToRemove);
CGFloat newHeight = viewheight - spaceToRemove;
NSLog(@"NewHeight:%f",newHeight);
CGRect frame = CGRectMake(0 , navBarHeight + statusbarheight, self.view.frame.size.width, newHeight);
self.webView = [[UIWebView alloc]initWithFrame:frame];
//self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.webView];
self.webView.scalesPageToFit = true;
NSURL *url = [NSURL URLWithString:@"http://example.com/finnaRoot/index.php"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestURL];
self.webView.scrollView.showsVerticalScrollIndicator = false;
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
self.webView.delegate = self;
self.tabBarController.delegate = self;
self.webView.scrollView.delegate = self;
}
Log output, from an iPhone 5s
2014-11-26 17:19:21.184 Finna[14617:1765689] Height1:568.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] Height2:568.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] Height3:568.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] NAVHeight:44.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] TABHeight:49.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] StatbarHeight:20.000000
2014-11-26 17:19:21.185 Finna[14617:1765689] NAVHeight+TABHeight:113.000000
2014-11-26 17:19:21.186 Finna[14617:1765689] NewHeight:455.000000
The smaller content is actually a UIWebBrowserView, which I am having a hard time finding any information on. I have the code I am using below, as well as a log output to insure all the numbers are correct. My questions are, 1) Is there a better way to set the webview to span the screen area between the top and bottom bars for all devices?
For information about basic view behaviors, see View Programming Guide for iOS. In addition to HTML content, UIWebView objects can be used to display other content types, such as Keynote, PDF, and Pages documents. For the best rendering of plain and rich text in your app, however, you should use UITextView instead.
While it has been available in Forms for a long time now, the default was still the UIWebViewRenderer. Shortly after the introduction of iOS 13, Apple decided to send out warning messages about the UIWebView deprecation. The warning would read: ITMS-90809: Deprecated API Usage – Apple will stop accepting submissions of apps that use UIWebView APIs.
This warning was still a warning and would not prevent you from publishing your app at the time. A few months after this, Apple announced that as of April 2020 they reject new apps still referencing UIWebView. For updates to apps the deadline is December 2020. Of course, we want to be ready well before then, and we are.
I've encountered with the same problem.
And found simple fix.
The culprit is UIViewController
's property automaticallyAdjustsScrollViewInsets
. UIViewController
reference says:
Default value is
YES
, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar.
It means that UIViewController
adds that top gap to UIWebView
's scroll view even if you properly set up webview frame or add autolayout constraints. To overcome this behaviour just
Set to
NO
if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.
"manage scroll view inset adjustments your self" in our context means that we won't add any insets ;)
same issue with any scroll view, i.e. Blank space at top of UITextView in iOS 10 https://stackoverflow.com/search?q=automaticallyAdjustsScrollViewInsets
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With