LoginSignup
3
2

More than 5 years have passed since last update.

UIButtonの上にUIPanGestureRecognizerを置いたとき、UIButtonにはどういうイベントが発生するのか

Posted at

概要

UIPanGestureRecognizer(ドラッグ・スワイプ)を使った挙動を実装する必要があった。
しかしその領域にはUIButtonがあったのだった。

UIButtonの上で、UIPanGestureRecognizerに拾われる操作をしたとき、
一体UIButtonにはどんなイベント(UIControlEvents)が走るのか?

結論

[self.button addTarget:self action:@selector(cancelButton) forControlEvents:UIControlEventTouchCancel];

UIPanGestureRecognizerに操作が拾われた場合、UIButtonには上記のイベントが走る。

UIControlEventTouchCancel は キャンセルイベントが発生したときのイベント名だけど
こういうときに動くらしい。

UIControlEventTouchDown // これはUIPanGestureRecognizerで拾われるドラッグ操作するとき、最初のタップ時にイベント発生。
UIControlEventTouchUpOutside // これは発生しない
UIControlEventTouchDragExit // これも発生しない

こういうイベントとは別になるので要注意だった。

3
2
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
3
2