以编程方式隐藏工具栏

时间:2014-04-19 20:37:49

标签: ios uitoolbar

我发现了很多讨论,但是对我来说,任何工作都没有问题。 我在viewcontroller中创建了一个toolBar:

UIToolbar *toolBar =[[UIToolbar alloc]initWithFrame:CGRectMake(0,[[UIScreen mainScreen]bounds].size.height - 49,[[UIScreen mainScreen] bounds].size.width, 49)];

[toolBar setTranslucent:YES];

UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

UIBarButtonItem *buttonfb = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fb.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(condividiFB)];
UIBarButtonItem *buttontw = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"twitter.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(condividiTW)];

NSArray *toolbaritems = [NSArray arrayWithObjects:flexibleSpace, buttonfb,flexibleSpace, buttontw,flexibleSpace, nil];
toolBar.items = toolbaritems;

[self.view addSubview:toolBar];

没关系。工具栏非常可爱,但我想在滚动过程中隐藏或移动它。 我检测到滚动并使用以下解决方案调用方法但不起作用。 当我试图隐藏工具栏时,两者都没有。 我尝试了很多我在这里解决的解决方案。 例如:

[self.toolBar removeFromSuperview];

但没有; 另一种方式:

[_toolBar setHidden:YES];

既不;

尝试移动:

self.toolBar.frame = CGRectMake(self.toolBar.frame.origin.x, self.toolBar.frame.origin.y + 100, self.toolBar.frame.size.width, self.toolBar.frame.size.height);
没什么作用。 我疯了。

1 个答案:

答案 0 :(得分:0)

使用您定义的属性设置工具栏,而不是示例中的本地范围变量。

改变这个:

UIToolbar * toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0,[[UIScreen mainScreen]bounds].size.height - 49,[[UIScreen mainScreen] bounds].size.width, 49)];

对此:

self.toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0,[[UIScreen mainScreen]bounds].size.height - 49,[[UIScreen mainScreen] bounds].size.width, 49)];
相关问题