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?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With