iOS11 UIBarButtonItem 不工作

iOS11 UIBarButtonItem not working

我有一个在应用商店上架的应用程序。我正在努力为 iOS11 版本做好准备,但 运行 遇到了一个恼人的问题。

应用程序中 UIBarButtonItem

None 工作正常。 leftBarButtonItems 是可点击的,但点击区域稍微偏向该项目的右侧。 rightBarButtonItems 根本不起作用!我已经通过情节提要和代码添加了项目,但其中 none 似乎有效。请帮忙!

举个例子:-

navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Save", comment: "save button title"), style: UIBarButtonItemStyle.plain, target: self, action: #selector(VC.rightBarButtonClicked(_:)))

iOS11 UIBarButtonItem action not get called

运行 相同,对我来说,解决方案是使用 xcode 8.3 构建(具有 ios11 运行 的设备,8.3 构建的应用程序运行良好)

您可以使用此解决方法在 xcode 8.3

上调试 ios11 设备

是的,iOS 11 中存在错误,因此您可以使用其他方法。

一样使用interactivePopGestureRecognizer
 self.navigationController?.interactivePopGestureRecognizer?.delegate = self as! UIGestureRecognizerDelegate

并实现像

这样的委托方法
 func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        guard gestureRecognizer == interactivePopGestureRecognizer else {
            return true // default value
        }

        // Write you code here.
    }

有同样的问题。它归结为我们项目中名为 "UIButton+MinimumTouchArea.swift" 的文件中 UIButton 的扩展,它覆盖了 UIButton.hitTest 并破坏了 iOS 11 中的 UIBarButtonItem。我们花了一整天的时间才弄明白!