One Quickie


Discriminating single and double tap gesture (UIView->General)
You want a single tap to do something, and a double tap to do something else. You don't want the single tap to fire unless it's fer sher not a double-tap. (assuming you can live for the timeout before your single tap gesture happens). You can make the single-tap recognizer wait until the double-tap one fails:
    UITapGestureRecognizer *singleTap =
        [[UITapGestureRecognizer alloc] initWithTarget: self
                                        action: @selector(startStop:)];
    singleTap.numberOfTapsRequired = 1;
    singleTap.numberOfTouchesRequired = 1;
    [self addGestureRecognizer: singleTap];

    UITapGestureRecognizer *doubleTap =
        [[UITapGestureRecognizer alloc] initWithTarget: self
                                        action: @selector(resetTimer:)];
    doubleTap.numberOfTapsRequired = 2;
    doubleTap.numberOfTouchesRequired = 1;
    [self addGestureRecognizer: doubleTap];

    [singleTap requireGestureRecognizerToFail: doubleTap];

    [singleTap release];
    [doubleTap release];



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com