UIWebBrowserView does not cover the entire UIWebView

So, I'm trying to make this simple behavior, working on my iPhone application for a while. I have a navigation bar at the top and a tab bar at the bottom. I upload all my content to a webview that I want to set between them. I already posted this issue twice,

both here: iOS View still not loading in the correct position

and here: Programmatically setting content to fill the screen between the tab bar and the navigation controller

Currently my webview looks and works fine on iPhone 4 and 4, the problem occurs on 5s. When the screen finishes loading, it looks like the image here: http://grosh.co/screen.jpg . This happens both on the simulator and on the devices.

After further verification, I found that the UIWebView actually works correctly (the gray areas you see are webviews). Smaller content is actually a UIWebBrowserView , which makes it difficult for me to find information.

I have the code that I use below, as well as log output to ensure that all numbers are correct. My questions:

1) Is there a better way to set up web browsing to cover the area of โ€‹โ€‹the screen between the top and bottom columns for all devices?

2) If not, is there a way to install UIWebBrowser to cover the entire web view?

I tried iterating over the webview areas as described here: http://normansoven.com/ios-webview/#.VHyOUr6Jnww , but I never saw webBrowserView.

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 Out With 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 
+6
source share
2 answers

I ran into the same problem. And found a simple fix. The culprit is the UIViewController property automaticallyAdjustsScrollViewInsets . UIViewController link says:

The default value is YES , which allows the view controller to adjust scrolling depending on the areas of the screen consumed by the status bar, navigation bar and toolbar or tab bar.

This means that the UIViewController adds the top space to the UIWebView scrollbar, even if you set the webview frame correctly or added autodetection restrictions. To overcome this behavior, simply

Set NO if you want to control the scroll insert settings yourself, for example, when there are more than one type of scroll in the view hierarchy.

"manage scroll insert settings in their own form" in our context means that we will not add any insertions;)

same problem with any kind of scroll, i.e. Empty space at the top of a UITextView in iOS 10 https://stackoverflow.com/search?q=automaticallyAdjustsScrollViewInsets

+8
source

This issue also appeared on the iPhone X.

With iOS 11, UIScrollView now has the contentInsetAdjustmentBehavior property.

webview.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

can fix this problem.

+3
source

Source: https://habr.com/ru/post/978761/


All Articles