嗨我有导航项目有一个视图,其中包含两个标签我为导航元素内部的视图添加了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上运行
感谢您的帮助
答案 0 :(得分:1)
我解决了它添加以下代码
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
}
使高度和宽度约束处于活动状态是另一个问题的答案我目前没有链接到它将在编辑中发布链接(目前我无法找到该问题)
答案 1 :(得分:0)
我遇到同样的问题并且也使用此代码解决了:
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = false
self.navigationItem.largeTitleDisplayMode = .automatic
var width = popUserChatView.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)).width - 15.0
let height = popUserChatView.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 = popUserChatView.widthAnchor.constraint(equalToConstant: width)
let heightConstraint = popUserChatView.heightAnchor.constraint(equalToConstant: height)
heightConstraint.isActive = true
widthConstraint.isActive = true
}
在ViewDidLoad()中调用