草庐IT

iOS swift : Adding or Moving NavigationBar to bottom of the view controller

coder 2023-09-13 原文

我想将导航 Controller 栏移动到 View Controller 的底部。我怎样才能完成这项工作?

我试过了:

self.navigationController!.navigationBar.frame = CGRectMake(
        0,
        UIScreen.mainScreen().bounds.height - 50,
        UIScreen.mainScreen().bounds.width,
        50)

这是移动到底部但隐藏了所有其他 Controller 对象并且后退按钮也没有唤醒。

最佳答案

苏杰联合国,

您不应尝试将嵌入式 UINavigationController 提供的 UINavigationBar 移动到屏幕底部。尝试这样做会明显移动其下方的所有 View ,从而导致所有 Controller 对象隐藏。

解决方法

方法 1:

考虑使用工具栏 :)

工具栏被设计为放置在屏幕底部。如果您使用的是 xib 或 Storyboard,您可以从组件库中选择工具栏并将其放置在 ViewController 的底部,然后适本地应用自动调整掩码或约束:)

现在为了显示后退按钮,请使用 UIBarButtonItems。将样式更改为自定义并为其提供箭头图像或提供默认样式。

虽然现在你已经准备好了 :) 你会注意到 View Controller 顶部的 UINavigationBar。为了摆脱它,

选择您的 ViewController,选择其 TopBar 属性将其设置为 none :)

方法 2

使用 UINavigationBar。

特定于使用导航栏并且不想使用工具栏,那么您也可以使用 UINavigationBar 做同样的事情。

将组件库中的 UINavigationBar 拖到屏幕底部。将 UIBarButtonItem 拖放到 leftBarButtonItem,将 barButtonItem 图像更改为您的背面图像。 (与 UIToolBar 相同的过程只是使用 UINavigationBar 代替)

了解这与嵌入式 NavigationController 提供的导航栏不同。因此,就像我上面在这里解释的那样,摆脱 ViewController 顶部的 NavigationBar

最后,

在这两种情况下,从条形按钮项绘制一个 IBoutlet 并以编程方式处理弹出 viewController。

快乐编码:)

关于iOS swift : Adding or Moving NavigationBar to bottom of the view controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37318724/

有关iOS swift : Adding or Moving NavigationBar to bottom of the view controller的更多相关文章

随机推荐