0
1

More than 3 years have passed since last update.

UICollectionViewにLongPressGestureRecognizerで長押しをつける

Posted at

長押ししたセルに任意の操作ができます。

こちらの記事を元にしています。
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
        }
    }
}

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

Core MLを使ったアプリを作っています。
機械学習関連の情報を発信しています。

Twitter
Medium

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1