UIView Clipped By Statusbar until Autorotate

情到浓时终转凉″ 提交于 2019-12-07 04:05:36

问题


Ive created a multiview application that uses multiple controllers to display and control views. The problem Im having is, when the simulator initially loads the view the header is partially covered by the bar at top of screen and the tool bar at the base is not touching the base of the screen. I used the Interface builder size attributes to control the view when the iphone rotates and it works perfectly. All smaps into place perfectly both in landscape and portrait mode AFTER a rotation but the problem is with the initial load before a rotation occurs. Your thoughts a much appreciated. Tony


回答1:


I've had issues with views being clipped by status, nav, and tab bars. I've fixed most of them by using the Simulated Metrics feature in Interface Builder. That way what your laying out in IB is a lot more accurate to what your actually going to get.




回答2:


I grappled with this issue for days and days--no amount of fiddling in IB worked.

Ultimately I got it to work by adding this line:

mainViewController.view.frame = window.screen.applicationFrame;

to the application:didFinishLaunchingWithOptions: method. (Where mainViewController is the primary UIViewController).




回答3:


I ran into this issue too. Specifically, when displaying an ADBannerView, my whole view would shift and be under the status bar and leave a little empty space just the size of the status bar at the bottom of the iPhone screen. Here's how I solved it : (Adam's answer here helped me figure this out):

// In the function that displays an iAD Banner
CGRect contentFrame = self.view.bounds;
CGRect myStatusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGFloat statusHeight = myStatusBarFrame.size.height;

// Set the view's origin to be under the status bar.

contentFrame.origin.y = statusHeight;

I needed to set the origin of my view to be below the Status bar, and that solved the issue for me.




回答4:


The problem is that you're adding your controller "incorrectly" according to Apple docs (although IMHO Apple designed it badly - the default should be that you don't need to shift!)

if you're going to have a status bar, Apple requires that you "manually" shift all your controllers down by 20 pixels (more accurately, by the height of the statusbar - although that's always 20 pixels today, Apple lets you request the height at runtime, from the "statusBarFrame" property in UIApplication)

Apple's classes - e.g. UINavigationController / UITabBarController - automatically shift themselves down by 20 pixels when they're added to the screen. Both classes have a bug where they will do this shift even if they are not the main controller - so your app suddenly shifts down an extra 20 pixels, leaving 20 pixels of white space at top.

But, when they rotate, those classes often "get it right" and move back into place. Or vice versa.

c.f. this link for a much more detailed explanation of what's going on, and how to write your code the way Apple wants you to:

http://blog.red-glasses.com/index.php/tutorials/iphone-auto-rotation-for-intermediate-developers-tutorial-1/



来源:https://stackoverflow.com/questions/487150/uiview-clipped-by-statusbar-until-autorotate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!