Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Tap gesture state begin doesn't hit

I have made a view clickable with a tap gesture recognizer, which is working just fine. But I want to highlight the view when the touch happens en remove it when the touch ended.

I have tried this:

- (IBAction)refresh:(UITapGestureRecognizer *)sender {
    if(self.currentStatus == NODATA){
        if(sender.state == UIGestureRecognizerStateBegan){
            NSLog(@"Began!");
            [self.dashboardViewController.calendarContainer state:UIViewContainerStatusSELECTED];
        }
        if (sender.state == UIGestureRecognizerStateEnded){
             NSLog(@"%@", @"Ended");
            [self.dashboardViewController.calendarContainer state:UIViewContainerStatusNORMAL];
        } 
        [self setState:REFRESHING data:nil];
    }
}

The NSLog of "Ended does" get displayed but the began didn't so it never goes into selected. Why is this?

like image 407
Haagenti Avatar asked Nov 19 '13 10:11

Haagenti


1 Answers

UITapGestureRecognizer will never go in the UIGestureRecognizerStateBegan state. Only continuous gestures (such as a swipe or a pinch) will result for their recognizers going from UIGestureRecognizerStatePossible to UIGestureRecognizerStateBegan. Discrete gestures, such as a tap, put their recognizers directly into UIGestureRecognizerStateRecognized, i.e. for a single tap, right into UIGestureRecognizerStateEnded.

That said, maybe you're looking for a UILongPressGestureRecognizer, which is a continuous recognizer that will enter UIGestureRecognizerStateBegan, allowing you to discern beginning and end of touch?

like image 104
triazotan Avatar answered Oct 15 '22 00:10

triazotan