UICollectionViewにLongPressGestureRecognizerで長押しをつける
長押ししたセルに任意の操作ができます。
こちらの記事を元にしています。
https://ofsilvers.hateblo.jp/entry/uicollectionview-and-long-press
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(onLongPressAction))
longPressRecognizer.allowableMovement = 10
longPressRecognizer.minimumPressDuration = 1
self.collectionView.addGestureRecognizer(longPressRecognizer)
@objc func onLongPressAction(sender: UILongPressGestureRecognizer) {
let point: CGPoint = sender.location(in: self.collectionView)
let indexPath = self.collectionView.indexPathForItem(at: point)
if let indexPath = indexPath {
switch sender.state {
case .began:
print(indexPath)
default:
break
}
}
}
🐣
フリーランスエンジニアです。
お仕事のご相談こちらまで
[email protected]
Core MLを使ったアプリを作っています。
機械学習関連の情報を発信しています。
Author And Source
この問題について(UICollectionViewにLongPressGestureRecognizerで長押しをつける), 我々は、より多くの情報をここで見つけました https://qiita.com/john-rocky/items/5ddff918a6f18607c65e著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .