-1

What are the different ways to recognize a UIButton being touched?

IBAction doesn't seem to be working with what I want, to my knowledge, I could probably use a gesture recognizer and check if the button's location was tapped, but is there any other way?

Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90
user3266395
  • 85
  • 1
  • 8
  • 4
    What do you mean "IBAction doesn't seem to be working with what I want"? What are you trying to do? Post some code if possible. – Gad Feb 04 '14 at 12:47
  • Be specific to your question...just read your question once..Do you think that anybody here will help you for what you have just asked? – Ajay Feb 04 '14 at 12:50
  • @GadMarkovits please refer to this link: http://stackoverflow.com/questions/21550771/does-changing-a-buttons-title-prevent-further-action?noredirect=1#comment32548774_21550771 - after I change a button's title, the IBaction function associated with it is no longer called ; also, to ajay sometimes I may be ambiguous but I think my question is quite clear. IBAction is not recognising my button's touching in certain situations, and I want to work around it – user3266395 Feb 04 '14 at 12:52

2 Answers2

0

Try UITapGestureRecognizer.

//-- For identifing touch recognize

    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchIdentifier:)];
    singleTapGestureRecognizer.numberOfTapsRequired = 1;
    singleTapGestureRecognizer.enabled = YES;
    singleTapGestureRecognizer.cancelsTouchesInView = NO;
    [your_button addGestureRecognizer:singleTapGestureRecognizer];

Method for operation

-(void)touchIdentifier:(UITapGestureRecognizer*)gesture
{
    NSLog(@" Current button ID %d \n",gesture.view.tag);
}
Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90
0

hello U can go with the UISwipe Recognier

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]
                                        initWithTarget:self action:@selector(handleSwipe:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[imgView_ addGestureRecognizer:swipeRight];        
[swipeRight release];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]
                                        initWithTarget:self action:@selector(handleSwipe:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[imgView_ addGestureRecognizer:swipeLeft];
[swipeLeft release];    

But DO NOT forget to set UserInteractionEnabled for the View