iOS11 UIBarButtonItem不起作用

4
我有一个在应用商店上线的应用程序。我正在尝试为iOS11发布做好准备,但遇到了一个令人讨厌的问题。
应用程序中的所有UIBarButtonItem都无法正常工作。leftBarButtonItems可点击,但单击区域略微偏右。rightBarButtonItems根本不起作用!我已经通过storyboard和代码添加了这些项目,但似乎没有一个能够正常工作。请帮忙!
以下是一个例子:
navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Save", comment: "save button title"), style: UIBarButtonItemStyle.plain, target: self, action: #selector(VC.rightBarButtonClicked(_:)))

你能检查一下安全区域吗?请参考 - https://developer.apple.com/documentation/uikit/uiview/positioning_content_relative_to_the_safe_area - user1046037
3个回答

6

我曾遇到同样的问题。这是由于我们项目中一个名为 "UIButton+MinimumTouchArea.swift" 的文件中的 UIButton 扩展重写了 UIButton.hitTest 方法,导致在 iOS 11 下破坏了 UIBarButtonItem。我们花费了一整天的时间才弄清楚原因!


谢谢!原来是之前的开发人员覆盖了按钮的hitTest区域,导致出现问题! - Rajeev Bhatia

1

1
感谢您的回复。这也是我现在正在做的,但应该有一种方法可以使用Xcode9解决此问题,因为我制作了一个示例应用程序并下载了另一个开源项目,两者都可以正常工作。 - Rajeev Bhatia

0

是的,在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.
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接