iPhone:如何检测哪次触摸已经结束?

发布于 2024-10-19 01:39:24 字数 156 浏览 6 评论 0原文

在我的应用程序中,我想检测用户何时松开第二根手指并只在屏幕上握住一根手指。

问题是我的 TouchesEnded:withEvent: 显示 [[event allTouches] count] 为 2。

我如何检测哪一个触摸仍保留在屏幕上?

谢谢。

In my app I want to detect when the user lift off his second finger and is holding only one on the screen.

The problem is that my touchesEnded:withEvent: shows [[event allTouches] count] to be 2.

How can I detect which one of the touches remains on the screen?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各自安好 2024-10-26 01:39:24

当用户进行触摸时,会触发 TouchBegan 方法。您可以将指针保持在出现的第一个触摸处。在触摸结束之前它不会改变。

编辑:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ([touches count] == 1)
    {
        if (!myTouch) myTouch = [touches anyObject]; //I assume myTouch is set to nil in touchesEnded
    }
    else
    {
        //perform your logic for this case
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ( myTouch && [touches containsObject: myTouch]
    {
        //perform your logic
        myTouch = nil;
    }
}

我假设您的类中有一个变量UITouch *myTouch来处理触摸事件。

When touch is made by user touchesBegan method triggers. You can keep the pointer to the first touch appeared. It will not be changed until the touch ends.

EDIT:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ([touches count] == 1)
    {
        if (!myTouch) myTouch = [touches anyObject]; //I assume myTouch is set to nil in touchesEnded
    }
    else
    {
        //perform your logic for this case
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ( myTouch && [touches containsObject: myTouch]
    {
        //perform your logic
        myTouch = nil;
    }
}

I assume you have a variable UITouch *myTouch in your class that handles touch events.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文