TouchesBegan在显示屏的左侧延迟 [英] TouchesBegan delay on left hand side of the display

查看:160
本文介绍了TouchesBegan在显示屏的左侧延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在启用了3D触控功能的iPhone上,有一项功能是长时间按下屏幕的左侧并打开足够的力可让您更改哪个应用程序处于活动状态。因此,当在屏幕的左侧发生非移动触摸时,触摸事件被延迟一秒或两秒,直到iPhone验证用户没有尝试切换任务并且正在与应用交互。

On iPhone's with 3D touch enabled, there is a feature where long pressing the left hand side of the screen with enough force opens lets you change which app is active. Because of this, when a non-moving touch happens on the left hand side of the screen, the touch event is delayed for a second or two until the iPhone verifies that the user is not trying to switch tasks and is interacting with the app.

这是使用SpriteKit开发游戏时的一个主要问题,因为每当用户在手指的左边缘轻敲/握住手指时,这些触摸会延迟一秒。屏幕。我能够通过在游戏的主场景中注册 UILongPressGestureRecognizer 来解决这个问题,从而禁用 TouchesBegan 并实施自定义触摸功能(由手势识别器用作选择器):

This is a major problem when developing a game with SpriteKit, as these touches are delayed by a second every time a user taps/holds their finger on the left edge of the screen. I was able to solve this problem by registering a UILongPressGestureRecognizer in the main Scene of the game, thus disabling TouchesBegan and implementing a custom touches function (used as a selector by the gesture recognizer):

-(void)handleLongPressGesture:(UITapGestureRecognizer *)gesture {

    CGPoint location = [gesture locationInView:self.view];

    if (gesture.state == UIGestureRecognizerStateBegan)
    {
        //
    }
    else if (gesture.state == UIGestureRecognizerStateChanged)
    {
        //
    }
    else if (gesture.state == UIGestureRecognizerStateEnded)
    {
        //
    }
    else if (gesture.state == UIGestureRecognizerStateCancelled)
    {
        //

    }
}

-(void)didMoveToView:(SKView *)view {
    /* Setup your scene here */

    UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];

    longPressGestureRecognizer.delaysTouchesBegan = false;
    longPressGestureRecognizer.minimumPressDuration = 0;
    [view addGestureRecognizer:longPressGestureRecognizer];

    // continue
}

这个问题是我必须为我希望用户输入的每次触摸(包括同步触摸)实现手势识别器。这会干扰任何 touchesBegan 方法作为 SKSpriteNode 的子类, SKScene 等等,并且杀死了很多功能。

The problem with this is that I would have to implement a gesture recognizer for every touch (including simultaneous ones) that I expect the user to enter. This interferes with any touchesBegan methods as subclasses of SKSpriteNode, SKScene, etc. and kills a lot of functionality.

有没有办法禁用这个延迟?注册gestureRecognizer时,我能够将 delaysTouchesBegan 属性设置为false。我可以以某种方式为我的SKScene做同样的事吗?

Is there any way to disable this delay? When registering the gestureRecognizer, I was able to set delaysTouchesBegan property to false. Can I do the same somehow for my SKScene?

要查看此问题,您可以运行默认的SpriteKit项目,然后点击(保持一两秒钟)靠近屏幕的左侧。您将看到触摸屏幕与呈现 SKShapeNodes 之间存在延迟(而不是触摸屏幕上的任何其他位置)。

To see this issue in action, you can run the default SpriteKit project, and tap (hold for a second or two) near the left hand side of the screen. You will see that there is a delay between when you touch the screen and when the SKShapeNodes are rendered (as opposed to touching anywhere else on the screen).

*编辑1 *
对于那些试图找到解决此问题的方法,您可以保留手势识别器但设置其 cancelsTouchesInView 为false。使用手势识别器执行您需要执行的所有操作,直到TouchesBegan启动( touchesBegan 将在手势识别器识别触摸后大约一秒钟内接收相同的触摸事件)。一旦 touchesBegan 启动,您就可以禁用手势识别器中发生的所有事情。这对我来说似乎是一个草率的修复,但它现在有效。

* Edit 1 * For those trying to find a way to get around this for now, you can keep the gesture recognizer but set its cancelsTouchesInView to false. Use the gesture recognizer to do everything you need to do until TouchesBegan kicks in (touchesBegan will receive the same touch event about a second after the gesture recognizer recognizes the touch). Once touchesBegan kicks in, you can disable everything happening in the gesture recognizer. This seems like a sloppy fix to me, but it works for now.

仍然试图找到一个或多或少的正式解决方案。

Still trying to find a more-or-less formal solution.

推荐答案

我作为一名用户体验过这一点,实在令人讨厌。唯一对我有用的是禁用3D触控。否则触摸屏的左侧几乎没用。

I have experienced this as an user and it is really annoying. The only thing that worked for me was to disable the 3D touch. Otherwise the left side of the touchscreen is almost useless.

这篇关于TouchesBegan在显示屏的左侧延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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