嗨我有导航项目有一个视图,其中包含两个标签我已经为导航元素内的视图添加了userInteractionEnabled(IBoutleted as navigationView)
navigationView.isUserInteractionEnabled = true
mainTitleClicked = UITapGestureRecognizer(target: self, action: #selector(mainTitleTapped))
self.navigationView.addGestureRecognizer(mainTitleClicked)
这是在IOS 10中工作,但是当我在xcode 9中运行相同的代码时ios 11用户界面搞砸了并且手势无法识别
IOS 10版
IOS 11版
我应该改变什么才能使它适用于ios 11
谢谢您的帮助
最佳答案 我通过添加以下代码解决了它
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = false
self.navigationItem.largeTitleDisplayMode = .automatic
var width = navigationView.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)).width - 15.0
let height = navigationView.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)).height
let screenSize: CGRect = UIScreen.main.bounds
let windowWidth = screenSize.width
width = windowWidth * 0.55
let widthConstraint = navigationView.widthAnchor.constraint(equalToConstant: width)
let heightConstraint = navigationView.heightAnchor.constraint(equalToConstant: height)
heightConstraint.isActive = true
widthConstraint.isActive = true
}
使高度和宽度约束激活是另一个问题给出的答案我目前没有链接到它将在编辑中发布链接(目前我无法找到该问题)