TouchesBegan delay on left hand side of the display
Asked Answered
N

1

8

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.

Nikko answered 12/10, 2016 at 12:21 Comment(9)
Fighting the same problem. Even worse is that touches moved gets fired on 3d Touch devices without a change in the x or y coordinates i.e you didn't actually move your finger. I managed to get around that but I haven't solved the problem you described.Kazue
Yup, experiencing the same problem with the continuous touches moved calls.Nikko
On 3d Touch devices try and use Force Touch do do something in touches moved. For example in my game I have a player that would shoot when you tap and enter slowMotion when swipe and hold. Now I use force touch to get the pressure change to enter slow motion on 3D Touch devices and it feels great. Its very easy to implement, just google force touch pressure changes. Than for devices without 3d touch, this is what I do and I haven't had a problem with it yet, at least with my games. #36060923Kazue
@Kazue while I do agree its a workaround for the touchesMoved issue, my question is about a different problemNikko
Yeah, well you mentioned that you also have the move problem, so I wanted to offer a suggestion. In regards to your actual question, I dont think there is much you can do for now. I made bug report about this. Apple has been responding to all my reports recently so I will report back when I have something.Kazue
They need to adjuste/disable that feature when a game is open.Kazue
Just incase your are interested, even though apple has not replied to my bug report yet I did see that my report is a duplicate one. So someone already made a report and apple must be aware of it. Will report back if I got further news.Kazue
Same issue hear. For right now I'm showing the touch area for my controls to be slightly more to the right (as opposed to right against the left side).Dyedinthewool
Andriko13, check what I did here in case you consider it a better solution: #39813745Odometer
U
0

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.

Unscratched answered 3/9, 2017 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.