LoginSignup
0
0

More than 1 year has passed since last update.

画面をスワイプした事を検知(UISwipeGestureRecognizer)

Posted at

今回の内容 

  • 画面をスワイプした事を検知

コードと簡単解説

  • .directionには、.down .left .right .upから選択して使用します。

    • .downは下に向けてスワイプしたことを検知します。
    • .leftは左側に向けてスワイプしたことを検知します。
    • .rightは右側に向けてスワイプしたことを検知します。
    • .upは上に向けてスワイプしたことを検知します。
  • 4つ全てを使用する場合は、4つ分インスタンスを作成します。

  • .directionを設定しないで使用すると、右側に向けてスワイプした時に検知しました。

 override func viewDidLoad() {
        super.viewDidLoad()

        let swipeDetection = UISwipeGestureRecognizer(target: self, action: #selector(screenSwipe))
        swipeDetection.direction = .down

        view.addGestureRecognizer(swipeDetection)
 }

@objc func screenSwipe(){

        //スワイプを検知した時の処理
    }

終わり

ご指摘、ご質問などありましたら、コメントまでお願い致します。

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