首页 文章

如何在Swift中没有导航控制器的情况下将导航栏添加到视图中

提问于
浏览
1

swift中我的导航栏有问题 . 我将viewController更改为另一个:

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

    let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("GameViewController") as GameViewController
    nextViewController.transitioningDelegate = self.transitionManager
    self.presentViewController(nextViewController, animated:true, completion:nil)

但是当我看到我的第二个viewController时,它正在做一个有很多ViewController可能性的应用程序游戏而且我不能使用Segue,因为这段代码不在 @IBAction func

如何在没有导航控制器的情况下添加带有条形按钮项的导航栏?

这里是Obj-C的同一个问题:How to add Navigation bar to a view without Navigation controller

最好的祝福

1 回答

  • 4

    要执行此操作,您可以使用IB:将左窗格中的 Navigation Bar 拖到 UIViewController 上 . 如图所示:

    enter image description here

    要根据设备正确制作 Navigation Bar 尺寸,您需要添加约束以将顶边固定到视图顶部,并将左右边缘都固定到视图的左侧和右侧(高度是内在的并且不是'需要约束) . 这也可以在IB中完成:

    enter image description here

    完成这两个步骤后,您可以像平常一样使用 Navigation Bar - 例如,我在第一张图像中添加了 Bar Button ItemNavigation Bar .

相关问题