iOS-UIControlEvents详解

UIControlEvents包含Common, UISlider, UIButton, UITextField, Other几类。

Common UIControlEvents

UIControlEvent Condition
UIControlEventTouchDown 在控件中按下未松开时触发
UIControlEventTouchDownRepeat 在控件中多次按下时触发
UIControlEventTouchUpInside 在控件中按下并松开时触发
UIControlEventTouchUpOutside 在控件中按下,移动到控件外松开时触发
UIControlEventTouchDragInside 在控件中按下并拖动时触发
UIControlEventTouchDragOutside 在控件中按下,移动到控件外拖动时触发
UIControlEventTouchDragEnter 在控件中按下并拖动到控件外,重新拖动回控件时触发
UIControlEventTouchDragExit 在控件中按下并拖动到控件外,离开控件时触发
UIControlEventTouchCancel 由于系统事件中断时触发,例如,控件被移除等
UIControlEventAllTouchEvents 所有TouchEvent都会触发

UISlider UIControlEvent

UIControlEvent Condition
UIControlEventValueChanged UISlider滑动时触发

UIButton UIControlEvent

UIControlEvent Condition
UIControlEventPrimaryActionTriggered UIButton上进行操作结束时触发,例如点击松开,拖动松开等

UITextField UIControlEvents

UIControlEvent Condition
UIControlEventEditingDidBegin 弹出键盘,开始编辑时触发
UIControlEventEditingChanged 内容发生变化时触发
UIControlEventEditingDidEnd 收起键盘时触发
UIControlEventEditingDidEndOnExit 按下Return键时触发,随后收起键盘会触发UIControlEventEditingDidEnd
UIControlEventAllEditingEvents 所有EditingEvent都会触发

Other UIControlEvents

UIControlEvent Condition
UIControlEventApplicationReserved 保留值以便应用使用
UIControlEventSystemReserved 保留值以便系统使用
UIControlEventAllEvents 所有Event都会触发

举例说明

1.在UIButton中,按下并拖动到Button外松开,依次触发:

Down > DragInside > DragExit > DragOutside > UpOutside

2.在UIButton中,按下并拖动到Button外,再拖动回Button内松开,依次触发:

Down > DragInside > DragExit > DragOutside > DragEnter > DragInside > UpInside