摘要:
- UIControlEventTouchDown
- UIControlEventTouchDownRepeat
- UIControlEventTouchDragInside
- UIControlEventTouchDragOutside
- UIControlEventTouchDrag...
UIButton的點擊態
UIButton的點擊事件狀態UIControlEvents主要有如下幾種:
UIControlEventTouchDown = 1 << 0, // on all touch downs
UIControlEventTouchDownRepeat = 1 << 1, // on multiple touchdowns (tap count > 1)
UIControlEventTouchDragInside = 1 << 2,
UIControlEventTouchDragOutside = 1 << 3,
UIControlEventTouchDragEnter = 1 << 4,
UIControlEventTouchDragExit = 1 << 5,
UIControlEventTouchUpInside = 1 << 6,
UIControlEventTouchUpOutside = 1 << 7,
UIControlEventTouchCancel

如上圖
UIControlEventTouchDrag 相關事件
注意:在下面演示過程中,1~4過程中要保持手指一直子啊屏幕上, 不要抬起手指
1.當手指在屏幕 A點 上按下去,就會觸發這個事件 UIControlEventTouchDown
2.緊接著,不要松開手指,從 A點 滑動到 B點 ,這段事件內,會不斷的觸發 UIControlEventTouchDragInside事件
3.緊接著,不要松開手指,從 B點 滑動到 D點 ,這段時間內會觸發3個事件:
注意: C點 是UIButton的邊界點
從 B點 滑動到 C點 過程中, 會不斷的觸發 UIControlEventTouchDragInside當經過 C點 時,會觸發一次 UIControlEventTouchDragExit 事件當從 C點 滑動到 D點 過程中,會不斷的觸發 UIControlEventTouchDragOutside
4.緊接著,不要松開手指,從 D點 返回,滑動到 B點 ,這段時間內會觸發3個事件:
從 D點 滑動到 C點 過程中, 會不斷的觸發 UIControlEventTouchDragOutside當經過 C點 時,會觸發一次 UIControlEventTouchDragEnter 事件當從 C點 滑動到 D點 過程中,會不斷的觸發 UIControlEventTouchDragInside
UIControlEventTouchUpInside
在UIButton上按下手指后,不論你是否拖動手指,或者拖到手指到UIButton外, 只要你最終抬起手指的時刻,你的手指是處在UIButton 內 ,就會觸發此事件
例如,以下操作均會觸發此事件:
在 A點 按下手指后,然后抬起手指,就和平常的單擊事件一樣;
在 A點 按下手指后,拖動手指到B點,然后抬起手指;
在 B點 按下手指后,拖動手指到 D點 ,然后再拖回 B點 ,然后抬起手指
UIControlEventTouchUpOutside
在UIButton上按下手指后,拖動手指,無論你拖動手指進出UIButton多少次, 只要你最終抬起手指的時刻,你的手指是處在UIButton 外 ,就會觸發此事件
例如,以下操作均會觸發此事件:
在 B點 按下手指后,滑動手指到 D點 后,抬起手指;
在 B點 按下手指后,滑動手指到 D點 -》A點 -》 B點 -》 D點 , 只要最終抬起手指在UIButton外(即 D點 )即可。
UIControlEventTouchCancel
按鈕的觸摸事件被打斷,會觸發此事件。
手指在 UIButton 內按鈕, 這期間可以任意滑動,但不要抬起手指, 在抬起手指之前觸摸事件被打斷,就會觸發此事件;例如,在抬起手指前,突然彈出一個UIAlertView時,就會打斷按鈕的觸摸事件
UIControlEventTouchDownRepeat
多點觸摸按下事件,點觸計數大于1:用戶按下第二、三、或第四根手指的時候。