0

How do I do two action on button click event.For example on single click I do one action and on two clicks continuously I have to do another event.

user1987342
  • 33
  • 1
  • 2

4 Answers4

1

Use double tap gesture ..... on a UIImageView . Dont forget to set the UIImageView's UserInteractionEnabled to TRUE.

ImageView.userInteractionEnabled = YES;
IronManGill
  • 7,222
  • 2
  • 31
  • 52
1

Here tapCount is int variable that declare in .h file

- (void)viewDidLoad
{
  tapCount = 0; // Count tap on Slider 

 UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ButtonTap:)];
    [button addGestureRecognizer:gr];
    
}

 - (void)ButtonTap:(UIGestureRecognizer *)g 
    {
/////////////// For TapCount////////////

        tapCount = tapCount + 1;
        NSLog(@"Tap Count -- %d",tapCount);

/////////////// For TapCount////////////



if (tapCount == 1)
{

       // code for first tap
}
else if (tapCount == 2)
{
      // Code for second tap
}
    
}
Nimantha
  • 6,405
  • 6
  • 28
  • 69
iPatel
  • 46,010
  • 16
  • 115
  • 137
1

Set your initial button tag to 0

then

-(IBAction)yourBtnPress:(id)sender
{
    UIButton *btn = (UIButton*)sender;
    if (btn.tag==0)
    {
        btn.tag=1;
        //singlePress
    }
    else if(btn.tag==1)
    {
        //double tap

        //if you want other action then change tag
        btn.tag=2;

        //if you restart task then
        btn.tag=0;
    }

}
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
0

You can use conditional setAction:

If single touch then call selectorSingleTouch.

else call selectorDoubleTouch.

//this is not compiler checked... atleast you may get some idea from this

UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doSingleTap)];
singleTap.numberOfTapsRequired = 1; 
[self.view addGestureRecognizer:singleTap];

UITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doDoubleTap)];
doubleTap.numberOfTapsRequired = 2; 
[self.view addGestureRecognizer:doubleTap];
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140