cortex
cortex

Reputation: 699

Check for double tap in editing mode

I'm making a tweak that involves popping an alert whenever the user double taps an icon in editing mode. I've tried hooking on to

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

of SBIcon and then

{
    %orig;
    UITouch *touch = [touches anyObject];
    if (touch.tapCount == 2 && [[objc_getClass("SBIconController") sharedInstance] isEditing])
    {
        //pop an alert and do stuff
    }
}

But this doesn't seem to work at all. Could anyone tell me what is wrong with the above and suggest alternative ways to achieve this?

EDIT: I'm using theos, if it matters.

Upvotes: 2

Views: 248

Answers (2)

ipraba
ipraba

Reputation: 16553

Alternative ways for you

If your icon is a button then you can easily detect the Double tab by adding UIControlEventTouchDownRepeat event

[yourIconButton addTarget:self action:@selector(multipleTap:withEvent:) 
             forControlEvents:UIControlEventTouchDownRepeat];



-(IBAction)multipleTap:(id)sender withEvent:(UIEvent*)event 
{
   UITouch* touch = [[event allTouches] anyObject];
   if (touch.tapCount == 2) {
     // Do all your actions here
   }
}

If you are considering it for a whole view then use UITapGesture

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[tap setNumberOfTapsRequired:2];
[yourIconView addGestureRecognizer:tap];


- (void)tapAction:(UIGestureRecognizer *)gestureRecognizer
{
    //Do your action
}

Upvotes: 1

Tripti Kumar
Tripti Kumar

Reputation: 1581

I will suggest you to use Tap gesture recognizer.It is more specific and works very accurately.

For more info you can check out this link: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html

Upvotes: 1

Related Questions