ios - 检测在“单元”上单击了哪个“视图”
问题描述
当我单击单元格上的任何 UIImageView 时,我有三个UIImageView
单一Cell
的,我想检测单击了哪个onCellSelection
,而不UITapGestureRecognizer
在每个单元上放置一个UIImageview
func SocialViewRow(address: SocialMedia)-> ViewRow<SocialMediaViewFile> {
let viewRow = ViewRow<SocialMediaViewFile>() { (row) in
row.tag = UUID.init().uuidString
}
.cellSetup { (cell, row) in
// Construct the view
let bundle = Bundle.main
let nib = UINib(nibName: "SocialMediaView", bundle: bundle)
cell.view = nib.instantiate(withOwner: self, options: nil)[0] as? SocialMediaViewFile
cell.view?.backgroundColor = cell.backgroundColor
cell.height = { 50 }
print("LINK \(address.facebook?[0] ?? "")")
cell.view?.iconOne.tag = 90090
//self.itemDetails.activeURL = address
let openFace = UITapGestureRecognizer(target: self, action: #selector(QuickItemDetailVC.openFace))
let openT = UITapGestureRecognizer(target: self, action: #selector(QuickItemDetailVC.openTwit))
let you = UITapGestureRecognizer(target: self, action: #selector(QuickItemDetailVC.openYouYub))
cell.view?.iconOne.addGestureRecognizer(openFace)
cell.view?.iconTwo.addGestureRecognizer(openT)
cell.view?.iconThree.addGestureRecognizer(you)
cell.frame.insetBy(dx: 5.0, dy: 5.0)
cell.selectionStyle = .none
}.onCellSelection() {cell,row in
//example
//print(iconTwo was clicked)
}
return viewRow
}
解决方案
使用UITapGestureRecogniser
(or UIButton
) 将是更好的方法。这些类用于此类任务。
如果您仍想使用不同的方法,请将方法添加到您的单元子类(替换imageView1, imageView2, imageView3
为您自己的属性)
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
let point = touch.location(in: view)
if imageView1.frame.containsPoint(point) {
// code for 1st image view
} else if imageView2.frame.containsPoint(point) {
// code for 2nd image view
} else if imageView3.frame.containsPoint(point) {
// code for 3rd image view
}
}
文件:
推荐阅读
- asp.net - Error: XML transformation error in Azure Pipelines
- javascript - 通过javascript用表单替换div innerHTML后无法提交
- python - 根据时间戳合并 pandas 数据帧
- php - 按标题名称(或索引)从 CSV 中删除列
- ruby-on-rails - 为什么在 Rails 中创建方法而不是从前端存储并且是使用 Postman
- sql-server - 如何正确分区表?
- python - 将 SWIG 用于 C++ 结构中的 std::vector 成员
- json - 如何在 React 中使用 JSON 数据
- python-3.x - Python urllib.request 和 urllib.error 用法
- octave - 在 CSV 导入到数据框时跳过了第一行