【问题标题】:Why is height of window 480 when applicationFrame height is 460?为什么applicationFrame高度为460时窗口高度为480?
【发布时间】:2013-02-13 04:08:07
【问题描述】:

我在 AppDelegate 类中创建了一个 TabBar VC,通过 [[UIScreen mainScreen] bounds] 设置窗口框架。由于我显示了一个状态栏,因此高度应该是 460,但它似乎是 480。如果我手动将高度设置为 460,它会将触摸识别切到选项卡的底部。下面是代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIColor *brownNavBarColor = [[UIColor alloc] initWithRed:0.78f green:0.56f blue:0.06f alpha:1.0f];
[application setStatusBarHidden:NO];

CGRect windowRect = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:windowRect];

CGRect appFrame = [[UIScreen mainScreen] applicationFrame];

NSLog(@" appFrame %f", appFrame.origin.y);
NSLog(@" appFrame %f", appFrame.size.height);

NSLog(@" window.frame %f", self.window.frame.origin.y);
NSLog(@" window.frame %f", self.window.frame.size.height);

NSLog(@" window.bounds %f", self.window.bounds.origin.y);
NSLog(@" window.bounds %f", self.window.bounds.size.height);

[self.window makeKeyAndVisible];

self.ingredientTabVC2 = [[NewIngredientViewController alloc] initWithNibName:nil bundle:NULL];
self.ingredientNC2 = [[UINavigationController alloc] initWithRootViewController:self.ingredientTabVC2];
[self.ingredientNC2.navigationBar setTintColor:brownNavBarColor];

self.ingredientTabVC3 = [[IngredientTabViewController alloc] initWithNibName:nil bundle:NULL];
self.ingredientNC3 = [[UINavigationController alloc] initWithRootViewController:self.ingredientTabVC3];
[self.ingredientNC3.navigationBar setTintColor:brownNavBarColor];

self.tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:NULL];
self.tabBarController.viewControllers = [[NSArray alloc] initWithObjects: self.ingredientNC2, self.ingredientNC3, nil];


[self.window setRootViewController:self.tabBarController];
return YES;
}

这给出了日志输出

2013-02-12 23:04:21.867 SingleTest[24221:c07]  appFrame 20.000000
2013-02-12 23:04:21.868 SingleTest[24221:c07]  appFrame 460.000000
2013-02-12 23:04:21.869 SingleTest[24221:c07]  window.frame 0.000000
2013-02-12 23:04:21.870 SingleTest[24221:c07]  window.frame 480.000000
2013-02-12 23:04:21.870 SingleTest[24221:c07]  window.bounds 0.000000
2013-02-12 23:04:21.871 SingleTest[24221:c07]  window.bounds 480.000000

有人可以解释这种差异背后的原因吗?

【问题讨论】:

  • 在ios状态栏框架高度为20

标签: ios objective-c uiwindow appdelegate


【解决方案1】:

来自UIScreen 的文档:

应用框架:

此属性包含屏幕边界减去状态栏占用的区域(如果可见)。使用此属性是检索应用程序初始窗口大小的推荐方法。矩形以点为单位指定。

界限:

包含屏幕的边界矩形,以磅为单位。 (只读)

bounds 包含状态栏,applicationFrame 不包含。

还要注意applicationFramey 起源是20

您希望主窗口填满屏幕。当您设置窗口的rootViewController时,它会自动调整为applicationFrame

【讨论】:

  • 所以它将 applicationFrame 放在窗口内并将 rootViewController 与 applicationFrame 匹配?
猜你喜欢
  • 1970-01-01
  • 2012-08-02
  • 2015-02-26
  • 1970-01-01
  • 1970-01-01
  • 2012-11-21
  • 2016-10-05
  • 2016-07-15
  • 1970-01-01
相关资源
最近更新 更多