在使用 hidesBottomBarWhenPushed 推送动画期间,工具栏位置不正确 [英] Toolbar incorrectly positioned during push animation with hidesBottomBarWhenPushed
问题描述
我有一个使用 Tabbar 进行基本导航的应用程序.从 Tabbar 的一个屏幕中,我想输入另一个屏幕,该屏幕显示一个工具栏而不是 Tabbar,并在顶部显示一个后退导航项.
这样做的最佳方法是什么?如果我使用Hide Bottom Bar on Push"(又名 hidesBottomBarWhenPushed)并在屏幕上添加一个工具栏,我可以在工具栏放置在屏幕底部之前看到一个移除标签栏的动画.
UITableViewController
带工具栏的解决方案(需要代码)
使用来自 .
I have an App using a Tabbar for basic Navigation. From one of the screens of the Tabbar I want to enter another one that shows a toolbar instead of the Tabbar and a back navigation item on the top.
What is the best way to do this? If I use "Hide Bottom Bar on Push" (aka hidesBottomBarWhenPushed) and add a Toolbar to the screen I can see an animation removing the Tabbar before the Toolbar is placed at the bottom of the screen.
Solution for UITableViewController
with toolbar (requires code)
Using code from this answer, I was able to achieve the same effect, but with the toolbar at the bottom of a table view.
Add this to your table view controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setToolbarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setToolbarHidden:YES animated:YES];
}
Important note: placing these calls in viewWillAppear
and viewWillDisappear
instead of viewDidLoad
makes this easier to handle, as it will work reliably even for multiple pushes and pops of the same view controller, and you won't have to clean up after it in the previous view controller.
And configure it like this in the storyboard:
Also, enable Hides bottom bar when pushed in the storyboard, or in your code, for the view controller being pushed.
Then you can add toolbar buttons to the toolbar in the storyboard.
Build and run, and you get this effect:
Here's a complete sample project demonstrating this.
这篇关于在使用 hidesBottomBarWhenPushed 推送动画期间,工具栏位置不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!