Delay with touch events

前端 未结 4 386
逝去的感伤
逝去的感伤 2021-01-14 22:36

We have an app in AppStore Bust~A~Spook we had an issue with. When you tap the screen we use CALayer to find the position of all the views during their animation and if you

相关标签:
4条回答
  • 2021-01-14 22:51

    Delayed touches usually indicates a CPU overload. Using a NSTimer for frame-to-frame based action is prone to interfering with the touch handling.

    If that's the case for your app, then my advice is very simple: OpenGL.

    0 讨论(0)
  • 2021-01-14 22:53

    Are you using a UIScrollView to host all this? There's a property of that called delaysContentTouches. This defaults to YES, which means the view tries to ascertain whether a touch is a scroll gesture or not, before passing it on. You might try setting this to NO and seeing if that helps.

    0 讨论(0)
  • 2021-01-14 23:02

    If you're doing any sort of core-animation animation of the CALayers at the same time as you're hit-testing, you must get the presentationLayer before calling hitTest:, as the positions of the model layers do not reflect what might be on screen, but the positions to which the layers are animating.

    Hope that helps.

    0 讨论(0)
  • 2021-01-14 23:03

    This is a pretty old post about a seasonal app, so the OP probably isn't still working on this problem, but in case others come across this same problem and find this useful.

    I agree with Kriem that CPU overload is a common cause of significant delay in touch processing, though there is a lot of optimization one can do before having to pull out OpenGL. CALayer is quite well optimized for the kinds of problems you're describing here.

    We should first check the basics:

    • CALayers added to the main view's layer
    • touchesBegan:withEvent: implemented in the main view
    • When the phase is UITouchPhaseBegan, you call hitTest: on the main view's layer to find the appropriate sub-layer
    • Die sequence starts on the relevant model object, updating the layer.

    Then, we can check performance using Instruments. Make sure your CPU isn't overloaded. Does everything run fine in simulator but have trouble on the device?

    The problem you're trying to solve is very common, so you should not expect a complex or tricky solution to be required. It is most likely that the design or implementation has a basic flaw and just needs troubleshooting.

    0 讨论(0)
提交回复
热议问题