<分区>
将我的手机更新到 iOS 14 后,我无法再与我的应用程序的 UICollectionViewCell
或 UITableViewCell
中的内容进行交互。运行 iOS 14 的 iOS 模拟器中也存在此问题,但在 iOS 13 及以下版本中一切正常。
我的单元格中有按钮和其他 Collection View ,它们不再可交互。就好像整个单元格内容都变成了静态一样。下面是我的 UICollectionViewCells
和 UICollectionViewController
中的一些代码,但是 UITableViewCells
中也存在同样的问题。我正在使用 Swift 5。didSelectItemAt
和类似的功能工作正常,它在单元格的 contentView
中交互,特别是似乎不起作用。如有必要,我可以粘贴更多代码,因为我修剪了一些绒毛和其他我已缩小范围以不成问题的代码。
由于 UICollectionViewCell
和 UITableViewCell
都存在这个问题,我相信我在更基本的层面上做错了。
UICollectionViewCell
中的相关代码:
override init(frame: CGRect) {
super.init(frame: frame)
setupContainers()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupContainers() {
// Adding subviews like so...
addSubview(subviewToAdd)
// Anchor all subviews using NSConstraints
}
然后是UICollectionViewController
中的相关代码
override func viewDidLoad() {
super.viewDidLoad()
setStyleAndDelegates()
}
private func setStyleAndDelegates() {
collectionView?.backgroundColor = UIColor.white
collectionView?.delegate = self
collectionView?.dataSource = self
collectionView?.register(MyCell.self, forCellWithReuseIdentifier: eventCellId)
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: eventCellId, for: indexPath) as! MyCell
return cell
}
编辑:
进一步检查 View 层次结构后,在 iOS 14 中,有一个额外的 UIView
直接放置在单元格中的所有内容之上。在 iOS 13 中,此 View 不存在。下面附上图片。