gpt4 book ai didi

ios - 为什么applicationFrame高度为460时窗口480的高度?

转载 作者:行者123 更新时间:2023-12-01 17:26:38 26 4
gpt4 key购买 nike

我在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

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

最佳答案

UIScreen的文档中:

applicationFrame:

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

范围:

包含屏幕的边界矩形,以点为单位。 (只读)
bounds包括状态栏,而applicationFrame不包括。

还要注意applicationFramey起源是20

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

关于ios - 为什么applicationFrame高度为460时窗口480的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14846229/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com