我正在为类似书籍的应用程序使用具有不同 View 的 Storyboard。在每个 View 中,我都希望有一个带有点击时出现的按钮的工具栏,让用户可以选择返回主视图。我通过 UITapGestureRecognizer 实现了这一点。但是,使用当前代码,当我进入 View 时,我的工具栏不会隐藏。当我点击它时,它就会像我想要的那样消失。如何进行切换,使工具栏默认隐藏,并在点击时显示?
这是我的代码:
@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];
}
最佳答案
当您的 View 加载时隐藏UIToolBar
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleNavBar:)];
[self.view addGestureRecognizer:gesture];
self.topBar.hidden = YES;
}
关于storyboard - 通过点击显示/隐藏 UIToolbar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15493529/