2013-02-13 1 views
1

Je crée un VC TabBar dans ma classe AppDelegate, en définissant le cadre de la fenêtre par les limites [[UIScreen mainScreen]]. Comme j'ai une barre d'état affichée, la hauteur devrait être de 460, mais elle semble être de 480. Si je règle manuellement la hauteur à 460, elle coupe la reconnaissance tactile dans la partie inférieure des onglets. Voici le codePourquoi la hauteur de la fenêtre 480 est-elle atteinte lorsque la hauteur de l'applicationFrame est de 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; 
} 

Cela donne la sortie du journal

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 

Quelqu'un peut-il expliquer la raison de cette différence?

+0

dans la barre d'état ios la hauteur du cadre est de 20 – NANNAV

Répondre

8

De la documentation pour UIScreen:

applicationFrame:

Cette propriété contient les limites de l'écran moins la zone occupée par la barre d'état, si elle est visible. L'utilisation de cette propriété est recommandée pour récupérer la taille initiale de la fenêtre de votre application. Le rectangle est spécifié en points.

limites:

Contient le rectangle de délimitation de l'écran, mesurée en points. (Lecture seule)

bounds comprend la barre d'état, applicationFrame ne fonctionne pas.

Notez également que le applicationFrame a une origine y de 20.

Vous souhaitez que la fenêtre principale remplisse l'écran. Lorsque vous définissez le rootViewController de la fenêtre, il sera automatiquement ajusté au applicationFrame.

+0

Ainsi, il place l'applicationFrame à l'intérieur de la fenêtre et adapte le rootViewController à l'applicationFrame? – user2066978

+0

Oui, c'est correct. – rmaddy

+0

merci, cela efface les choses. – user2066978

Questions connexes