【问题标题】:Navigation structure without using standard Apple Navigation Bars (Swift)不使用标准 Apple 导航栏 (Swift) 的导航结构
【发布时间】:2014-11-18 16:31:51
【问题描述】:

是否可以使用 Interface Builder 设置导航结构,而不使用标准的 Apple 导航栏?我想将打开新视图控制器的操作应用于我自己的自定义按钮。

这是不可能的吗,你们有什么好地方可以让我在不使用界面生成器的情况下开始学习这样做吗?

【问题讨论】:

  • 有什么问题吗?但我不想在我的应用程序中使用来自 Apple 的标准导航栏。

标签: ios swift navigation interface-builder


【解决方案1】:

您必须在根视图控制器中嵌入导航控制器。为此,在情节提要中选择您的视图控制器,单击编辑器->嵌入->导航控制器。

在 viewDidload 中写入 self.navigationController?.navigationBar.hidden = true

在顶部有一个导航栏大小的标签,在其上添加一个按钮,并在其操作方法中编写以下代码

@IBAction func goToNextController(sender: AnyObject)
    {
        let second = self.storyboard?.instantiateViewControllerWithIdentifier("second") as SecondViewController

        self.navigationController?.pushViewController(second, animated: true)
    }

这里的 secondViewController 是我们要推送的

在 secondViewcontroller 的顶部同样有一个标签和按钮,并在按钮的操作方法中编写以下代码

![@IBAction func previousButtonTapped(sender: AnyObject)
    {
        self.navigationController?.popViewControllerAnimated(true)
    }][2]

【讨论】:

  • 谢谢!我到处找这个!最后一个问题:popViewControllerAnimated 方法,它会完全关闭视图吗?喜欢破坏它所以不使用不必要的内存?
【解决方案2】:

在 IB 中,您可以将导航栏的类更改为您自己的类。

如果你不使用 IB 你可以使用[[UINavigationController alloc] initWithNavigationBarClass:[MyNavBar class] toolbarClass:nil]

【讨论】:

  • 也就是说我可以完全自定义导航栏吧?
  • 没错。可以覆盖drawRect:,添加子视图等
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多