iOS Tap手势状态开始未命中 [英] iOS Tap gesture state begin doesn't hit

查看:67
本文介绍了iOS Tap手势状态开始未命中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用点击手势识别器使视图可点击,效果很好。但是我想突出显示发生触摸时的视图,并在触摸结束时将其删除。

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.

我已经尝试过:

- (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];
    }
}

显示 Ended do的NSLog,但是没有开始,所以它永远不会进入选定状态。为什么会这样?

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

推荐答案

UITapGestureRecognizer 将永远不会进入 UIGestureRecognizerStateBegan 状态。对于他们的识别器,只有连续手势(如滑动或捏)会从 UIGestureRecognizerStatePossible 变为 UIGestureRecognizerStateBegan 离散手势(例如轻击)将其识别器直接放置到 UIGestureRecognizerStateRecognized 中,即单击一次,直接放入 UIGestureRecognizerStateEnded

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.

也就是说,也许您正在寻找 UILongPressGestureRecognizer 一个连续的识别器,它将输入 UIGestureRecognizerStateBegan ,从而使您能够识别触摸的开始和结束?

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?

这篇关于iOS Tap手势状态开始未命中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆