TouchesBegan delay on left hand side of the display

我是研究僧i 提交于 2019-12-22 04:44:07

问题


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.

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
}

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.

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?

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).

* 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.


回答1:


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.



来源:https://stackoverflow.com/questions/39998489/touchesbegan-delay-on-left-hand-side-of-the-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!