2013-02-13 92 views
1

我在AppDelegate類中創建了一個TabBar VC,通過[[UIScreen mainScreen]邊界]設置窗口框架。由於我有一個狀態欄顯示,高度應該是460,但它似乎是480.如果我手動將高度設置爲460,它會將觸摸識別切割到標籤底部。下面是代碼爲什麼當applicationFrame高度爲460時窗口480的高度?

- (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 

有人能解釋這種差異背後的原因是什麼?

+0

在ios狀態欄框架高度是20 – NANNAV 2013-02-13 04:18:50

回答

8

從文檔爲UIScreen

applicationFrame:

此屬性包含屏幕邊界減去狀態欄佔用的面積,如果是可見的。推薦使用此屬性來檢索應用程序的初始窗口大小。矩形用點表示。

界限:

包含屏幕的邊界矩形,以點爲單位。 (只讀)

bounds包含狀態欄,applicationFrame沒有。

也請注意,applicationFramey來源20

您希望主窗口填滿屏幕。當您設置窗口的rootViewController時,它將自動調整爲applicationFrame

+0

因此,它將applicationFrame放置在窗口內,並將rootViewController放到applicationFrame中? – user2066978 2013-02-13 05:20:11

+0

是的,這是正確的。 – rmaddy 2013-02-13 05:42:07

+0

謝謝,這清除了事情。 – user2066978 2013-02-13 06:01:27

相關問題