我想在按下按钮时连续调用方法。我可以使用内部触摸或其他类似动作来检测UIButton按下状态。那么如何检测UIButton按压状态?
答案 0 :(得分:2)
我是这样做的:
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressRecordButton:)];
[self.view.recordBtn addGestureRecognizer:longPress];
UIButton *recordButton = self.view.recordBtn;
[recordButton addTarget:self action:@selector(beginTouchRecord:) forControlEvents:UIControlEventTouchDown];
[recordButton addTarget:self action:@selector(endTouch:) forControlEvents:UIControlEventTouchUpInside];
[recordButton addTarget:self action:@selector(endTouch:) forControlEvents:UIControlEventTouchCancel];
答案 1 :(得分:0)
您只能为此状态获取操作方法
typedef NS_OPTIONS(NSUInteger, 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 = 1 << 8,
UIControlEventValueChanged = 1 << 12, // sliders, etc.
UIControlEventEditingDidBegin = 1 << 16, // UITextField
UIControlEventEditingChanged = 1 << 17,
UIControlEventEditingDidEnd = 1 << 18,
UIControlEventEditingDidEndOnExit = 1 << 19, // 'return key' ending editing
UIControlEventAllTouchEvents = 0x00000FFF, // for touch events
UIControlEventAllEditingEvents = 0x000F0000, // for UITextField
UIControlEventApplicationReserved = 0x0F000000, // range available for application use
UIControlEventSystemReserved = 0xF0000000, // range reserved for internal framework use
UIControlEventAllEvents = 0xFFFFFFFF
};