Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting touches at launch on iOS

On Mac, one can always get the location of the mouse "outside the event stream" (ie, even if you've not subscribed to any delegate methods for mouseUp: et al) by calling [NSEvent mouseLocation].

Is there any way on iOS to get current touch events without listening to touchesBegan:?

I ask because there is at least one situation in which touchesBegan is not called: at app launch, if a touch is already in progress, touchesBegan is never called. In fact, neither are any of the touch-related UIEvent methods called as near as I can tell (nor UIApplication's / UIWindow's sendEvent:, apparently).

I would like to vary the behavior of my app slightly based on whether a touch is in progress at launch. Is there any way to detect an in-progress touch at app launch?

like image 398
SG1 Avatar asked Aug 12 '13 17:08

SG1


1 Answers

This cannot be done. The simple reason: The touch events don't belong to your app. Each touch belongs to some UI element (or responder). As you already know, this element gets the began, moved, ended, cancelled messages.

This is even true within a properly programmed app: All events regarding one touch are delivered to the very same object. After all, how would another object know what to do with that event, and how should the first object properly finish its expected behavior?

While you can (or could, but probably shouldn't) find a work around within your app, there's just no way for cross-app-touch passings.

And on the Mac you may query the mouse position, but in normal application flow there'll always be a mouse down before you get a mouse up event.

To be honest, I don't see any reason why this would be needed anyway... oh wait... I could split my app icon into several areas... not sure if it would already break privacy laws, though, if you get to know where the user has his icon on screen.

like image 106
Eiko Avatar answered Sep 28 '22 19:09

Eiko