如何在使用 UINavigationController setToolbarHidden:animated 时调整视图大小:

发布于 2024-10-14 09:06:48 字数 1103 浏览 1 评论 0原文

我正在使用 UINavigationController 工具栏。在显示它之前,我调整了视图的大小,以便它们不会被工具栏阻挡(我将当前视图控制器视图的框架设置为从 navigationBar 底部跨越到 。

但并非所有视图控制器都有 toolbarItems,因此,当从具有项目(控制器 A)的视图控制器切换到不具有项目的视图控制器时 (控制器 B),我想隐藏工具栏,但是,当我在 B 的 viewWillAppear:animated: 方法中调用 setToolbarHidden:animated: 时,工具栏在推送过程中动画向下。转换并显示其后面的 UIWindow 背景

这也会发生在相反的方向:当从 B 转换到 A 时(通过后退按钮),我希望工具栏以动画方式显示 A 的 。再次查看 ToolbarItems,但由于 A 的视图没有延伸到屏幕底部,因此 UIWindow 在弹出过渡期间是可见的,

这可能不是最好的描述,因此这里有一个。屏幕截图:

Cmd-shift-3 rapid-fire FTW

我尝试在其 viewWillDisappear:animated 中更新 A 的框架: 方法,但它做了奇怪的事情,因为它似乎是在 UINavigationController 推送动画块内调用的。任何见解将不胜感激。

更新:我尝试将工具栏隐藏在 B 的 viewDidAppear:animated: 中,但结果并不理想。使用此解决方案,在推送转换完成之前工具栏不会消失。由于 B 没有任何 toolbarItems,因此 A 的项目在转换过程中被推到左侧,在消失之前在屏幕上留下一个空的工具栏。另外,当返回 A 时,UIWindow 背景将可见,除非我将工具栏设置为在 B 的 viewWillDisappear:animated: 中可见,这意味着 B 必须知道A 有 toolbarItems

I'm using the UINavigationController toolbar. Before I display it, I resize my views so that they don't get blocked by the toolbar (I set the frame of the current view controller's view to the rect spanning from the bottom of the navigationBar to the top of the toolbar.

But not all of my view controllers have toolbarItems. So, when switching from a view controller that has items (controller A) to one that doesn't (controller B), I want to hide the toolbar. However, when I call setToolbarHidden:animated: in B's viewWillAppear:animated: method, the toolbar animates down during the push transition and shows the UIWindow background behind it.

This also happens in the reverse direction: when transitioning from B to A (via the back button), I want the toolbar to animate in to show A's toolbarItems again, but since A's view doesn't extend to the bottom of the screen, the UIWindow is visible during the pop transition.

That might not have been the best description, so here's a screenshot:

Cmd-shift-3 rapid-fire FTW

I have tried updating A's frame in its viewWillDisappear:animated: method, but it does strange things, since it seems to be called within the UINavigationController push animation block. Any insight would be appreciated.

Update: I tried hiding the toolbar in B's viewDidAppear:animated: instead, but the results weren't ideal. Using this solution, the toolbar doesn't get dismissed until the push transition completes. Since B doesn't have any toolbarItems, A's items get pushed to the left during the transition, leaving an empty toolbar on the screen before it disappears. Also, when going back to A, the UIWindow background will be visible unless I set the toolbar to visible in B's viewWillDisappear:animated:, which would mean that B has to know that A has toolbarItems.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ヤ经典坏疍 2024-10-21 09:06:48

也许最佳实践是在 B 的 viewDidAppear 中调用 setToolbarHidden:animated: ?

或者,您可以在自定义 UINavigationController 子类中的 pushViewController:animated: 方法中将 B 推送到导航控制器之前更改 A 的框架。

Maybe the best practice would be to call setToolbarHidden:animated: in B's viewDidAppear?

Or you can change A's frame before pushing B to navigation controller in a pushViewController:animated: method in a custom UINavigationController subclass.

翻了热茶 2024-10-21 09:06:48

由于我从未找到令人满意的涉及动画的解决方案,因此我最终将视图向下延伸到工具栏后面以避免显示窗口。如果你的控制器的视图是 UITableView 或 UIScrollView,你可以适当地设置它的 contentInset ,这样你的内容就不会被工具栏掩盖:

UIEdgeInsets edgeInsets = [[self tableView] contentInset];
if (![[self navigationController] isToolbarHidden]) {
    edgeInsets.bottom = CGRectGetHeight([[[self navigationController] toolbar] frame]);
}
[[self tableView] setContentInset:edgeInsets];

Since I never found a satisfactory solution to this involving animation, I ended up making my views extend down behind the toolbar to avoid showing the window. If your controller's view is a UITableView or UIScrollView, you can set its contentInset appropriately so that your content won't get covered up by the toolbar:

UIEdgeInsets edgeInsets = [[self tableView] contentInset];
if (![[self navigationController] isToolbarHidden]) {
    edgeInsets.bottom = CGRectGetHeight([[[self navigationController] toolbar] frame]);
}
[[self tableView] setContentInset:edgeInsets];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文