Iphone - UIToolbar自动位置

问题描述:

我有一个应用程序,UIToolBar将不断地在屏幕的底部。不管设备的方向如何。Iphone - UIToolbar自动位置

工具栏必须具有相同的屏幕宽度,并始终对底部进行调整。

如果设备旋转,工具栏必须采用新的宽度并继续在底部对齐。

有没有办法做到这一点编程?

感谢您的任何帮助。

首先,自动旋转可能有点棘手。例如,如果您使用的是UITabBarController,则需要对其进行子类化并添加适当的委托方法。您应该在通过Apple文档和Google自动旋转之前阅读,然后才能真正潜入。

要专门回答您的问题,以下是您需要声明UIToolbar以便它在您自动旋转时自动旋转安装该应用程序设置可以这样做:

// I keep this definition in a file called constants.h since I use it a lot 
#define SCREEN_FRAME [[UIScreen mainScreen] applicationFrame] 

UIToolbar *tb = [[[UIToolbar alloc]init]autorelease]; 
// this frame will position a toolbar at the bottom of the screen 
tb.frame = CGRectMake(0, 
      SCREEN_FRAME.size.height-tb.frame.size.height, 
      SCREEN_FRAME.size.width, 
      tb.frame.size.height); 
//Setting the auto-resizing mask will make the toolbar resize when the viewController 
//it resides in rotates. 
tb.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
+0

在iOS6上,init后的tb.frame是{{0,0},{0,0}} ... – Josejulio 2013-05-25 16:01:21

是的。看看自动调整口罩。

使用导航控制器,并利用toolbarItems property的。