关于界面底侧或者左右侧出侧一条空白(statusbar的高度问题) 20 pixel blank at bottom of screen

G了半天,才找到点线索,原因:

Adding the root view to your UIWindow can be complicated since the window always underlaps the status bar. The frame of your root view must therefore be reset to [[UIScreen mainScreen] applicationFrame] to prevent it from underlapping the status bar as well. We normally don't have to worry about this because UIViewController modifies the frame for us... except when it doesn't. Here's the deal:

  • If you create your view controllerand its view in the same NIB, and younest the view underneath the viewcontroller, it will adjust the view's frame automatically.
  • If you create your view controller andits view in the same NIB, but youconnect the view to the viewcontroller through the controller'sview outlet rather than nesting it, the controller will not adjust the view's frame automatically.
  • If you create your view controller in one NIB, and you connect it to a view defined in a detached NIB by setting the view controller's "NIB Name" property in IB, it will adjust the view's frame automatically, but only if you also have "Resize view from NIB" checked.
  • If you create your view controller by calling -initWithNibName:bundle:, it will not adjust the view's frame automatically.
  • UITabBarController expects its view to be added as the root view of the window, and therefore always adjusts its own view's frame to match the application frame automatically. (As a result you'll notice a weird 20 pixel gap if you ever add a UITabBarController's view as a subview of anything other than the window.)

I guess Apple figured that -initWithNibName:bundle: wouldn't typically be used to create the window's root view, so it doesn't adjust the frame in your case. Resizing it manually as you have done is fine, and is in fact recommended in the View Controller Programming Guide for iPhone OS, but you should really use [[UIScreen mainScreen] applicationFrame] since the status bar isn't always 20 pixels tall (e.g. it's taller when you're on a phone call.)


解决办法:

CGRect rct = loginController.view.bounds;
    rct = [[UIScreen mainScreen] applicationFrame];
    [loginController setWantsFullScreenLayout:YES];
    rct.origin.y = 20;
    loginController.view.frame = rct;


参考链接:

http://stackoverflow.com/questions/2247647/offset-on-uiwindow-addsubview

http://stackoverflow.com/questions/2166718/the-old-display-shifts-down-after-modal-view-controller-issue



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值