2013-03-22 12 views
7

dodam singTap i DoubleTap do widoku jak na poniższym kodzie:Wdrożenie singleTap i DoubleTap w Objective-C

-(void)awakeFromNib{ 
    [self setUserInteractionEnabled:YES]; 
    // 
    UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapGesture:)]; 
    doubleTapGesture.numberOfTapsRequired = 2; 
    [self addGestureRecognizer:doubleTapGesture]; 

    UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)]; 
    singleTapGesture.numberOfTapsRequired = 1; 
    [self addGestureRecognizer:singleTapGesture]; 
} 

-(void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTapGesture{ 
    [[self delegate] singleTapOnView]; 
} 

-(void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTapGesture{ 
    [[self delegate] doubleTapOnView]; 
} 

When DoubleTap singleTap również ogień. Jak wyłączyć singlet podczas DoubleTap? Dzięki!

Odpowiedz

11

Powiedz rozpoznawania jednego kranu że wymaga rozpoznawania dwukrotnie, by zawieść zanim wyzwala:

[singleTapGesture requireGestureRecognizerToFail:doubleTapGesture]; 

(jest to faktycznie kanoniczny przykład w UIGestureRecognizer docs for this method.)