开发者

iOS touch event

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?

T开发者_开发技巧hanks!

Sunny


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜