Assign diffrent targets for your button ControlEvents
There are many ControlEvents
available:
UIControlEventTouchDown = 1 << 0,
UIControlEventTouchDownRepeat = 1 << 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,
UIControlEventEditingDidBegin = 1 << 16,
UIControlEventEditingChanged = 1 << 17,
UIControlEventEditingDidEnd = 1 << 18,
UIControlEventEditingDidEndOnExit = 1 << 19,
UIControlEventAllTouchEvents = 0x00000FFF,
UIControlEventAllEditingEvents = 0x000F0000,
UIControlEventApplicationReserved = 0x0F000000,
UIControlEventSystemReserved = 0xF0000000,
UIControlEventAllEvents = 0xFFFFFFFF
Example:
[yourButton addTarget:self
action:@selector(methodTouchUpInside:)
forControlEvents: UIControlEventTouchUpInside];
- (void)methodTouchDown:(id)sender{
NSLog(@"TouchDown");
}
or Add gustures instead of assigning targets for ControlEvents
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[yourButton addGestureRecognizer: tapGesture];
- (void) handleTap:(UITapGestureRecognizer *)sender
{
if(sender.state == UIGestureRecognizerStateBegan)
{
NSLog(@"UIGestureRecognizerStateBegan");
}
else if(sender.state == UIGestureRecognizerStateEnded)
{
NSLog(@"UIGestureRecognizerStateEnded");
}
}
There are many UIGestureRecognizerState
available.
UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized