iOS 12 Navigation Bar bar Button 在取消弹出手势时变灰

标签 ios swift ios12

在我的演示项目中有两个 UIViewControllers,分别是 VC1 和 VC2。
此演示项目中没有任何其他附加代码。 enter image description here

VC1右栏按钮是灰色的 当我取消从VC2到VC1的pop时使用pop手势,然后使用pop手势或点击后退按钮弹出。
灰色样式看起来与禁用或突出显示相同。

enter image description here

但是按钮仍然可用,再次点击时样式恢复。
这是 iOS12 的错误吗?
我暂时没有低端设备和模拟器,我只在10.0、12.0、12.1上测试过。
iOS 10.0 运行正常,符合预期。
该错误似乎只发生在 iOS 12 及更高版本上。
有人对此有想法吗?

最佳答案

我找到了两个解决方案来解决这个问题:

将系统项从 Custom 更改为另一个,例如添加

enter image description here

enter image description here

这是一个更快的解决方案,但遗憾的是,您无法自定义此按钮。 要放置自定义按钮,您可以尝试其他解决方案:

从 Storyboard中删除 UIBarButtonItem,然后从代码中创建它们:

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Test", style: .plain, target: self, action: #selector(rightBarButtonTapped))
    }

    @objc func rightBarButtonTapped() {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc2 =  storyboard.instantiateViewController(withIdentifier: "viewController2")
        self.navigationController?.pushViewController(vc2, animated: true)
    }

    override func viewWillDisappear(_ animated: Bool) {
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Test", style: .plain, target: self, action: #selector(rightBarButtonTapped))
        super.viewWillDisappear(animated)
    }
}

请记住为要推送的 View Controller 设置Storyboard ID。在我的示例中,它是 viewController2

编辑:

您可以只添加 UIButton 而不是 UIBarButtonItem 就这样 ;) 您可以从 Storyboard 级别或编写代码来完成。

关于iOS 12 Navigation Bar bar Button 在取消弹出手势时变灰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53094840/

相关文章:

ios - React-Native View Component 按钮按下时的原生 iOS 导航

ios - Swift - UICollisionBehavior 委托(delegate)方法未被调用

ios - 如何以 QLPreviewController swift 语言显示 .doc 文件

objective-c - 在 iPhone X iOS 12 上从底部边缘向上滑动时停止应用程序进入后台

ios - 推送新的 UIViewController 时 UISearchController 消失

ios - Singleton 中的 NSMutableArrays 不保存值

iphone - 我的应用使用 URLRequest 登录两次

ios - 在没有 CAKeyframeAnimation 的情况下为沿着路径的 View 设置动画

ios - 如何扩展 Swift Dictionary 类型以返回非空 String 或 nil

swift - WKNavigationResponse 不再通过其 response.header 提供对 cookie 的访问