【发布时间】:2021-05-11 15:32:23
【问题描述】:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view
let tap = UITapGestureRecognizer(target: self, action: #selector(doubleTapped))
tap.numberOfTapsRequired = 2
view.addGestureRecognizer(tap)
}
@objc func doubleTapped(sender: UITapGestureRecognizer) {
let indexPath = self.collectionView.indexPathForItem(at: sender.location(in: sender.view))
if let unwrapped = indexPath {
由于某种原因,这里的 indexPath 总是为零。有人看到我的代码中的错误吗?
【问题讨论】:
-
试试
let indexPath = self.collectionView.indexPathForItem(at: sender.location(in: self.collectionView)) -
@Paulw11 谢谢!
标签: ios swift uitapgesturerecognizer indexpath