I am not too familiar with all the types of sent events, in Xcode, I only know touch up inside. What I am tying to do is perform one function when the user taps down and another when they have lifted their finger. What event would I use for this?
-
What's wrong with the "touch up inside" event? That is called when the user lifts their finger (while still inside the control). – rmaddy Apr 16 '15 at 19:53
4 Answers
In this question there's a example that handles a similar situation to what you are trying to do. I would suggest going through some more tutorials on how to create instances through the iOS dev program if you have access to their tools.
A simple way to do this would be to add a tap gesture recognizer on your view to do the same -
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(aMethod:)];
And then in the target method, check for different states of your tap gesture -
-(void)aMethod:(UIGestureRecognizer *)recogniser {
if(recogniser.state == UIGestureRecognizerStateBegan){
}
else if (recogniser.state ==UIGestureRecognizerStateEnded) {
}
}

- 387
- 2
- 3
- 16
I think what you probably want is this list of events you can subscribe to with a UIControl. The event you're using now is 'UIControlEventTouchUpInside', and your 'finger contact initiated' event is going to be 'UIControlEventTouchDownInside'.
These events are generated by subclasses of UIControl, of which UIButton is one. If you just need a rectangular area to get these events from, that'll be easier than implementing touch event handling manually.

- 123
- 5
A good way to handle this would be to setup two events, one using TouchUpInside
and the other using TouchDown
. This way you could hit the same (or different) action using different touch events:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn addTarget:self action:@selector(downAction:) forControlEvents:UIControlEventTouchDown];
[btn addTarget:self action:@selector(upAction:) forControlEvents:UIControlEventTouchUpInside];
Here is the doc source for the different control events you can use.

- 15,448
- 3
- 54
- 74