I've got a UIButton in my application called myButton. I'd like to react to a single finger tap and a two finger tap on the button differently. However, from what I understand UIButton objects are only able to detect single finger touches touchDown, touchUpInside, etc. After doing some research, it looks like I'll have to use the touchesBegan method and just check to see if both of the fingers are within myButton frame. Is there any easier way to do this? Thanks!
2
votes
Two thoughts: Could you override the button to look for a gesture? (I doubt that would be an "easier way" though.) Also, are you sure changing the behavior of a button will make it past the app store review?
- Marvo
I'm not sure if it would be easier or not. And this isn't going on the app store...this is just a personal creation.
- hemlocker
1 Answers
4
votes
Yes it is! By using UITapGestureRecognizer you can do something like this
- (void)viewDidLoad {
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]
tap.numberOfTapsRequired = 2;
[myButton addGestureRecognizer:tap];
[tap release];
}
- (void)tap:(UITapGestureRecognizer *)gesture {
NSLog(@"Tap!");
}