UILongPressGestureRecognizerでロングプレスを検知し、ロングプレスされたセルを調べたいです。
ここを参考にロングプレスは検知できるようになりました。
次にロングプレスされた地点はどこのセルかの検知です。
ここのサイトを参考に参考にロングプレス地点を取得しその地点をもとにセルを検知するコードを書いてみた(下のコード)のですが、情報が古く関数などの変更もあり、point
からセルを検知する事ができませんでした。
swift
1 // Long Press イベント 2 @objc func longPress(_ sender: UILongPressGestureRecognizer){ 3 // 押された位置でcellのPathを取得 4 let point = sender.location(in: uICollectionView) 5 let indexPath = UICollectionView.indexPathForItemAtPoint(point) 6 7 if indexPath == nil { 8 9 } else if sender.state == UIGestureRecognizer.State.began { 10 // 長押しされた場合の処理 11 print("長押しされたcellのindexPath:(indexPath?.row)") 12 } 13 }
let indexPath = UICollectionView.indexPathForItemAtPoint(point)
で__'CGPoint' is not convertible to 'UICollectionView'__とエラーが返ってきます。
どのようにセルを検知するのかを教えてください。
回答2件
あなたの回答
tips
プレビュー