1

I want to open a web browser i.e Google page on clicking a button. I am successfully getting this done on single click. But the same thing i want to achieve on double click of event. I searched a lot about this and got a program that opens on clicking anywhere on the screen. please guide me if anyone has any kinda knowledge about this.

Thanks in advance

Jose Luis
  • 3,307
  • 3
  • 36
  • 53

2 Answers2

0

try to use this for the event

UIControlEventTouchDownRepeat

mohammad alabid
  • 444
  • 7
  • 21
0

Try this:-

Suppose click is the action which gets called on :-

[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

What you have to do is:-

Make a BOOL global variable

in .h file do:-

BOOL isDoubleClick;
NSTimer *doubleClickTimer;

in .m file do:-

-(IBAction)click
{
    if (isDoubleClick==YES) {
        //DOUBLE CLICK
        isDoubleClick=NO;
    }
    else if(isDoubleClick==NO)
    {
        //SINGLE CLICK
        isDoubleClick=YES;
        doubleClickTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(TimerReload:) userInfo:nil repeats:NO];
    }
    NSLog(@"bool %s", isDoubleClick ? "true" : "false");

}

-(void)TimerReload:(NSTimer *)timer
{
    doubleClickTimer = nil;
    isDoubleClick = NO;
}

Explanation:-

First your isDoubleClick is NO.When you clicks on the button for the first time it gets YES.After that again you clicks on the second time if it gets YES Then it means it is a double click and do whatever you want to perform on double click.Make isDoubleClick to NO so that next time click is treated as single click.

Use of Timer:-

For double click you need to ensure that two time click is done one after another.For that enable a timer on single click and after 2 second fire a timer method to set isDoubleClick to NO to ensure that now if user clicks on the button , the click will be treated as single not double.

I hope it will save your couple of hours.

Happy Coding!!

Gypsa
  • 11,230
  • 6
  • 44
  • 82