我有一个导航栏,它是从另一个 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/