ios - 介绍 UINavigationController Swift

标签 ios swift uinavigationbar

我正在展示一个加载屏幕,我不想在其中显示导航栏。所以我用

self.navigationController.navigationBar.hidden = true

它可以隐藏导航栏。但是当我想显示导航栏时,我想在其中添加动画。

我试过使用这段代码,但没有出现该栏。

self.navigationController.setNavigationBarHidden(false, animated: true)

运行上面的代码后,栏仍然隐藏,我怎样才能显示/动画栏?

最佳答案

我认为你的方法已经是正确的了。您只需要知道将代码放在哪里。试试下面的代码。

ViewController 1 的代码

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.navigationBarHidden = true;
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.navigationController?.navigationBarHidden = true;
    }

    @IBAction func buttonTapped(sender: UIButton) {
        self.performSegueWithIdentifier("goToScreen2", sender: self)
    }
}

ViewController 2 代码

import UIKit

class ViewController2: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.navigationController?.setNavigationBarHidden(false, animated: true)
    }
}

更新答案:

我可以使用以下代码取消隐藏导航栏。

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBarHidden = true;
}

@IBAction func buttonTapped(sender: UIButton) {
    self.navigationController?.setNavigationBarHidden(false, animated: true)
}

实现的屏幕截图:-

enter image description here

关于ios - 介绍 UINavigationController Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25777530/

相关文章:

swift - 覆盖 didSet

ios - 呈现 View Controller 时设置后退按钮

iOS 7 改变 UINavigationBar titleView alpha

ios - 使用 Codable 解码具有多个 key 的 JSON

ios - 多个 UIswitches 一个随机按钮

ios - UITableView willDisplayCell 方法的不当行为

ios - iOS 7 中的长屏幕标题缺少后退按钮标题

ios - 向我的项目添加核心数据时无法添加 sql 文件

ios - 如何查找数组中的重复项?

swift - 为什么 Alamofire POST-Api-call 不起作用?