Question

Just curious. When the user touches the screen in an iPhone app, how does the OS handle the touch event? Does the current code block (function/method) finish, and then the touch event gets handled? Or does the OS interrupt whatever code may be running to handle the touch event?

Thanks!

Sunny

Was it helpful?

Solution

Touches to the screen cause the OS to generate touch events for your app. All events are handled in the main thread (the same thread that runs your code) which is implemented like a loop. The OS does not interrupt your code to handle an event; all events get handled at the next pass of the event loop.

OTHER TIPS

If the current function/method is running in the main thread, then any touch event handler will not be called until after the current routine returns (to the run loop). If the current function/method is not running in the main UI thread, then the code could be interrupted to run the touch event handler.

On current devices, touch events seem to be quantized to the 60 Hz frame rate, roughly every 16 mSec, so a physical touch may not be posted as an event until up to that time may have passed, and no handler will be called until after the event is posted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top