0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UIGestureRecognizerについてのメモ

Posted at

画面操作系(単タップ、長タップ、ダブルタップなど)

UIGestureRecognizer配下にある指による画面操作系の制御。全部で8個。
・UITapGestureRecognizer
・UIPinch
・UIRotation
・UISwipe
・UIPan
・UIScreenEdgePan
・UILongPress
・UIHover

●基本記法(例:UILongPress)

class GestureViewController: UIViewController, UIGestureRecognizerDelegate {

 // view系のUI
 let tableView: UITableView!

 // viewDidLoad内で宣言する
 override func viewDidLoad() {
      let longTap = UILongPressGestureRecognizer(target: self
                                                 action: #selector(tappedButton))

      // delegateは細かい設定をするときには必要なのかもしれない[要調査]
      longTap.delegate = self

      // view全体に適応させたいとき
      self.view.addGestureRecognizer(longTap)
      // 特定のviewに適応させたいとき
      self.tabelView.addGestureRecognizer(longTap)
 }

 @objc func tappedButton(_ gesture: UILongPressGestureRecognizer) {
      if gesture.state == .Began {
          print("タップしてます")
       } else if gesture.state == .Ended {
          print("指離しました")
       }
 }

}

storyboard上でも紐付けできるらしい。
UIはStoryboardで作ってジェスチャーはコードで紐付けとかできるんだろうか。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?