用水龙头显示/隐藏UIToolbar

时间:2013-03-19 07:13:32

标签: storyboard uitoolbar viewcontroller viewdidload uitapgesturerecognizer

我正在使用具有不同视图的故事板来制作类似书籍的应用。在每个视图中,我想要一个带有按钮的工具栏,该按钮会在点击时显示,这为用户提供了返回主视图的替代方法。我用UITapGestureRecognizer实现了这一点。但是,使用当前代码,当我进入视图时,我的工具栏不会被隐藏。当我点击它时,它会像我想要的那样消失。如何切换以便默认隐藏工具栏,然后点击它?

这是我的代码:

@implementation secondViewController 

- (void)toggleNavBar:(UITapGestureRecognizer *)gesture {
BOOL barsHidden = self.topBar.hidden;
self.topBar.hidden = !barsHidden;
}

- (void)viewDidLoad
{
[super viewDidLoad];
 UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self    
action:@selector(toggleNavBar:)];
[self.view addGestureRecognizer:gesture];


}

1 个答案:

答案 0 :(得分:4)

当您的视图加载时

隐藏 UIToolBar
- (void)viewDidLoad  
{  
 [super viewDidLoad];  
 UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleNavBar:)];   
 [self.view addGestureRecognizer:gesture];
 self.topBar.hidden = YES;
}