2012-06-22 28 views
0

我有一个带有工具栏的导航栏控制器。工具栏左侧只有一个按钮:信息灯。当我将视图旋转到横向时,工具栏仍然存在,但按钮不见了。视图处于横向模式时工具栏上的信息灯消失

我该如何让它留下来。我在IB查看了我的struts工具栏。它们被设置为留在工具栏的左下角。

我正在使用基本SDK 4.0版的iPod touch进行测试。

下面是代码:

UIButton *info = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[info addTarget:self 
      action:@selector(infoTap:) 
    forControlEvents:UIControlEventTouchUpInside]; 
/** Allocate and initialize the information button on the leftside of the toolbar. 
*/ 
UIBarButtonItem *infoItem = [[UIBarButtonItem alloc] initWithCustomView:info]; 
/** Use this to put space in before your info toolbar button. 
    */ 
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
/** Add buttons to the array. 
    */ 
NSMutableArray *items = [NSMutableArray arrayWithObjects: infoItem, flexItem, nil]; 
/** Add array of buttons to toolbar. 
    */ 
[self.toolbar setItems:items animated:NO]; 
/** Add the toolbar as a subview to the navigation controller. 
    */ 
[self.navigationController.view addSubview:toolbar]; 

有什么建议?

阿曼达

+0

你为什么使用UIBarButtonSystemItemFlexibleSpace?如果按钮位于工具栏的最左侧,则不需要该按钮。 –

回答

0

您发布的代码是你想做的事是正确的,所以问题的关键在于内支持代码。

我会检查几件事: 封闭的视图(self.navigationController.view)在循环中被调整大小?

什么是self.navigationController.view上的struts和autoresizingmasks?

什么是UIToolbar上的struts和autoresizingmasks? (我不确定你的意思是:“我检查了我的IB中的工具栏的支柱,它们被设置为留在工具栏的左下角。”工具栏怎么能留在左下角工具栏?)。

相关问题