ios - 如何设置导航栏的返回项

标签 ios swift uinavigationcontroller

我有一个导航栏,它是从另一个 View Controller 以模态方式呈现的,因此不会显示后面的项目,

我需要交叉溶解到第二个 View Controller ,并在其上放置一个导航栏,而不在第一个 View Controller 上放置一个导航栏,在第二个 View Controller 的导航栏上,后退按钮应该看起来与系统后退按钮完全相同。

最佳答案

如果您有导航栏并且需要自定义后退按钮,您可以这样添加:

let button = UIBarButtonItem(title: "Back Title", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(someMethod))
self.navigationItem.leftBarButtonItem = button

在选择器中,您可以关闭当前的 viewController 或调用其他返回方法

编辑

如果您需要一些具有标准推送过渡样式的自定义动画,您可以执行以下操作:

例如,在 Storyboard中使用 SecondViewController id 创建 viewController

在您的转换操作方法中进行如下操作:

func showSecondViewController() {
    guard navigationController != nil else {
        return
    }
    guard let secondViewController = storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") else {
        return
    }
    navigationController!.pushViewController(secondViewController, animated: false)
    UIView.transitionWithView(navigationController!.view, duration: 1, options: .TransitionCrossDissolve, animations: nil, completion: nil)
}

关于ios - 如何设置导航栏的返回项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39485969/

相关文章:

ios - 如何让 Chrome Cast 在 iOS 后台运行?

iphone - 创建并导入 swift 框架

ios - UINavigationBar 滑开而不是停留在原地

iOS - 导航栏没有后退按钮

iphone - 如何在 UIViewController 上没有 NavigationController 的情况下推送 DetailView

ios - 从混合应用程序的 UIwebview 访问 iOS native 属性/方法

ios - Google Photo Sphere 相机功能

objective-c - 使用 UIButtons 和 CoreAnimation 创建柔和的随机运动

swift - RealityKit 和 ARKit 的挑战

ios - 使用导航 Controller 推送后 UIScrollView 滚动不起作用