cálculo de la altura de UITabBar


Estoy escribiendo una aplicación que usa UITabBar para partes de la navegación. También estoy usando UIScrollView para presentar más información de la que normalmente puede manejar la pantalla. Debido a esto, necesito configurar la vista de desplazamiento para tener en cuenta la altura del UITabBar para que se muestre toda la información.

¿Hay una manera de calcular el height del UITabBar?

Author: CubeJockey, 2010-06-24

8 answers

Es 320 x 49.

Si desea probar, abrir Interfaz Builder, agregar un UITabBar, entrar en la regla, lo verá

UITabBar se hereda de UIView para que pueda usar el marco .Tamaño.altura para obtener la altura

 59
Author: vodkhang,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-06-24 03:19:32

Si el controlador de vista tiene un antepasado que es un controlador de barra de pestañas, puede recuperar la altura de esa barra de pestañas.

CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height;
 44
Author: Vladimir Shutyuk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-14 16:28:45

Estaba buscando hacer algo similar con centrar una etiqueta en la parte VISIBLE de la vista de un ViewController. Este ViewController pertenecía a un UITabBarController.

Aquí está el código que usé para centrar mi etiqueta:

UILabel *roomLabel = [[UILabel alloc] init];
CGRect frame = [[self view] bounds];
float tabBarHeight = [[[super tabBarController] tabBar] frame].size.height;
frame.size.height -= tabBarHeight;
[roomLabel setFrame:frame];
[[self view] addSubview:roomLabel];
[roomLabel release];

Observe que usé [[self view] bounds] no [[self view] frame] porque este último incluye la barra superior de 20 píxeles como el desplazamiento Y (que elimina el centrado vertical).

Espero que esto ayude a alguien!

Por cierto: Estoy usando iOS 4.3 y XCode 4 y el valor" hard-code " para la altura de la barra de pestañas sigue siendo 49 para mí!

 7
Author: mbm29414,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-21 13:53:34

Swift 3 +

let tabBarHeight = tabBarController?.tabBar.frame.size.height
print(tabBarHeight ?? "not defined")

Debe imprimir 49.0 (Tipo CGFloat)

 5
Author: Andrey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-09 15:30:21

Sé que esto no es ideal, pero realmente no quería tener un número mágico constante en cualquier lugar. Lo que hice fue crear un UITabBarController desechable, y obtener la altura a partir de ahí.

Hice esto también porque [UITabBar initWithFrame:] funciona como se desea, pero hacer un [bar setFrame:] no lo hace.

UITabBarController *dtbc = [[[UITabBarController alloc] init] autorelease];

CGRect tabRect = [[[self navigationController] view] frame];
tabRect.origin.y = tabRect.size.height - [[dtbc tabBar] frame].size.height;
tabRect.size.height = [[dtbc tabBar] frame].size.height;

tabBar_ = [[UITabBar alloc] initWithFrame:tabRect];

Lo que me gusta de esto es que colocará correctamente la barra de pestañas en la parte inferior del padre, independientemente del tamaño de los padres.

 3
Author: PKCLsoft,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-25 03:44:16

Esto debería funcionar en la mayoría de los casos en cualquier instancia de UIViewController:

bottomLayoutGuide.length
 3
Author: Alexander Borisenko,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-31 09:14:31

En Swift:

let height = self.tabBarController?.tabBar.frame.height ?? 49.0

Basándose en la altura real de la barra de tabulación, y usando el número mágico como reserva.

 2
Author: GK100,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-10 07:09:57

Así es como conseguí que funcionara en swift 4.1

Let tabBarHeight = CGFloat((self.tabBarController?.TabBar.marco.Tamaño.altura)!)

 0
Author: Graphics Factory,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-11 23:25:50