嗨,我有导航项,有一个视图,其中包含两个标签,我在导航元素中为视图添加了userInteractionEnabled (IBoutleted作为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上工作?
谢谢你的帮助
发布于 2017-10-13 07:26:15
我通过添加以下代码来解决这个问题
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
}使高度和宽度约束活动是在另一个问题中给出的答案,我目前没有链接到它,会在编辑中发布链接(目前我找不到这个问题)。
发布于 2017-10-13 14:06:59
我也有同样的问题,也用这个代码解决了:
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()
https://stackoverflow.com/questions/46342468
复制相似问题