IOS View still not loading in the correct position

I thought it cleared up, but apparently not. I use the code below to set the web view between the top nag panel and the tab bar below. This happens in my viewDidLoad () method. It worked great on all the simulators I tested it on, however, when I tested a friend of the iPhone 4s running 7.1.1, the webview displayed the entire width of the screen covered by the top nag and the bottom tabs.

How do I get the desired behavior on all devices and OS above 7?

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/notifications.php"]; NSURLRequest *requestURL = [NSURLRequest requestWithURL:url]; [self.webView loadRequest:requestURL]; self.webView.scrollView.showsVerticalScrollIndicator = false; self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor : [UIColor whiteColor]}; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.webView.delegate = self; self.webView.scrollView.delegate = self; 
0
source share
1 answer

This is because you are covering the entire view in your rectangle. You have to subtract the height and width of the tab and navigation bar.

take a look at this example

 - (void)viewDidLoad { [super viewDidLoad]; CGFloat viewheight = self.view.frame.size.height; CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height; CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height; CGFloat spaceToRemove = navBarHeight + tabBarHeight; CGFloat newHeight = viewheight - spaceToRemove; NSLog(@"%f",newHeight); NSLog(@"%f",self.view.frame.size.height); CGRect frame = CGRectMake(0 , 0 + navBarHeight, self.view.frame.size.width, newHeight); UIView *newView = [[UIView alloc]initWithFrame:frame]; newView.backgroundColor = [UIColor redColor]; [self.view addSubview:newView]; } 
+1
source

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


All Articles