UICollectionviewcell's contentView 中的 UITextfield 不注册水龙头



我在UICollectionViewCell的ContentView上添加了一个UITextfield,但点击UITextfield没有任何作用,文本字段也没有记录任何触摸。我仔细检查过的东西:

  • 键盘切换打开
  • ContentView为UserInteractionEnabled返回TRUE

除了将文本字段移动到UICollectionViewCell的常规视图(可以工作(之外,还有什么选项可以使contentView解决方案工作吗?

这是你的单元格高度问题。。。。你的contentView与你的单元格高度没有完全绑定,这就是为什么你没有得到点击事件

text字段即使在内容中也应接收点击查看

检查您的内容查看手机附带的所有边缘

override func awakeFromNib() {
super.awakeFromNib()
contentView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
contentView.leftAnchor.constraint(equalTo: leftAnchor),
contentView.rightAnchor.constraint(equalTo: rightAnchor),
contentView.topAnchor.constraint(equalTo: topAnchor),
contentView.bottomAnchor.constraint(equalTo: bottomAnchor)
])
}

最新更新