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.
Asked
Active
Viewed 111 times
0
-
1use touch or use double tap gesture on an imageview ... – IronManGill Jan 17 '13 at 14:21
-
See this SO discussion for some tips http://stackoverflow.com/questions/6179347/uibutton-long-press-event – jeffmurphy Jan 17 '13 at 14:24
-
use and find tap gesture you can get your answer – Bhavesh Lathigara Jan 17 '13 at 14:25
4 Answers
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
}
}
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