简体   繁体   English

如何更喜欢点击手势而不是绘制手势?

[英]How to prefer tap gesture over draw gesture?

In my view I'm overriding all the "touches*" methods to let the user draw on the screen. 在我看来,我覆盖了所有“ touches *”方法,以使用户在屏幕上绘画。 I'm recording the locations. 我正在记录位置。 In addition I have two gesture recognizers on my view to detect single tap and double tap. 另外,我的视图上有两个手势识别器,可检测单击和双击。 If I now move my finger just a little bit and short enough, I will be recording a small "draw" gesture. 如果我现在仅略微短一点地移动手指,我将记录一个小的“绘制”手势。 However when raising the finger, an additional tap gesture will be triggered. 但是,在举起手指时,将触发另一个轻击手势。 By trial and error I could possibly figure out a minimum time and movement threshold but I'm sure there are smarter ways? 通过反复试验,我可能会找出最短的时间和运动阈值,但是我确定有更聪明的方法吗? I need to know after how much movement and/or it is save to assume that no tap gesture will trigger. 我需要知道经过多少移动和/或保存之后才能假设没有轻击手势会触发。

You can avoid tap gestures. 您可以避免轻击手势。 Instead of that you can recognize taps in touch events itself. 取而代之的是,您可以识别触摸事件本身中的点击。

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
    if(touches.count == 1)
    {  

       if([[touches anyObject] tapCount] == 1)
       {
       // Do the action here for single tap
       }

       else if([[touches anyObject] tapCount] == 2)
       {
       // Do the action here for double tap
       }
    }
}

And you have to set a global bool variable for check whether user moved the finger on the screen. 而且,您必须设置一个全局布尔变量,以检查用户是否在屏幕上移动了手指。

BOOL _isMoved;

And make it TRUE in the touch move event 并在触摸移动事件中将其设置为TRUE

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {

    _isMoved = YES;
}

Before recording the track, you check whether this flag is TRUE or not? 在录制曲目之前,您检查此标志是否为TRUE? And also dont forget to make the flag to FALSE after saving the track 并且也不要忘记在保存曲目后将标志设置为FALSE

Hope this will help you :) 希望这个能对您有所帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM