2

I'm trying to load a UIView and then right away detect touches on that new view. Currently, overriding touchesBegan gives a delay of around a second.

So, I load up the UIView and immediately keep tapping on the screen. It takes around a second for touchesBegan to be called. From that point on, all is well. However, I can't afford the ~second wait initially.

I have stripped back all the code in the UIView to just the barebones incase anything was clogging up the main thread, but the delay still persists.

How can I go about getting immediate feedback of touches from a newly presented UIView? Thanks.

-- EDIT BELOW --

I've been playing around with this for the past few hours. Even when creating a custom UIWindow and overriding sendEvent, the UITouchPhase gets halted when the new view is displayed. To begin receiving events again I have to take my finger off the screen and place it back on the screen. (I don't want to have to do this).

The problem seems to lie with the segue to the new view controller. When it segues, the touch phase is ended. If I simply add a subview to the current view controller, I see the desired functionality (i.e. instant responding to touch).

Given my newly presented view contains a lot of logic, I wanted to wrap it all up in it's own view controller rather than add it to the presenter view controller. Is there a way for me to do this and use 'addSubview` to present it? This should hopefully achieve the desired effect.

cud_programmer
  • 1,244
  • 1
  • 20
  • 37

4 Answers4

2

In the end, I created a custom view controller with it's own xib. Where I would have segued, I now instantiate that custom view controller and append it's view. This has eliminated the touch lag.

cud_programmer
  • 1,244
  • 1
  • 20
  • 37
  • I'm facing with the same trouble here. http://stackoverflow.com/questions/33727638/ios-why-touchesbegan-has-some-delay-in-some-specific-area-in-uiview How did you solve your trouble? – TomSawyer Nov 16 '15 at 07:35
1

Have you disabled multi-touch? There's an inherent delay while the controller waits to see if there's a follow up touch (on all single touches). The initial sluggishness might be from loading up the multi-touch code and deciding what to do about it.

myViewController.view.multipleTouchEnabled=NO;
mark
  • 338
  • 1
  • 11
  • Tried disabling multiple touch, doesn't stop the delay unfortunately. I've also implemented a custom `UIWindow` and overridden `sendEvent`. Strangely, this also stops receiving/sending events during the delay period. – cud_programmer Sep 26 '14 at 19:02
0

As to your final question, look into view controller containment. Since iOS 5 Apple has provided the hooks officially and safely to present one view controller as a sub view of another.

Sadly I've no insight as to the greater issue.

Tommy
  • 99,986
  • 12
  • 185
  • 204
0

I found an answer that worked for me from a similar question asked here:

iOS: Why touchesBegan has some delay in some specific area in UIView

This solution isn't check-marked on that thread, so I'll copy it here to make it easier to find.

override func viewDidAppear(animated: Bool) {
    let window = view.window!
    let gr0 = window.gestureRecognizers![0] as UIGestureRecognizer
    let gr1 = window.gestureRecognizers![1] as UIGestureRecognizer
    gr0.delaysTouchesBegan = false
    gr1.delaysTouchesBegan = false
}
Andreas
  • 151
  • 2
  • 9