iOS 触摸事件调用流程

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
}

touchesBegan方法设置断点,控制台输入thread backtrace all,获取调用流程(调用顺序为打印出来的内容,从下往上执行:
1、线程“com.apple.main-thread”从“dyld`start + 520”开始执行。
2、线程“com.apple.uikit.eventfetch-thread”从“libsystem_kernel.dylib`__workq_kernreturn + 8”开始执行。

image.png
(lldb) thread backtrace all
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1
  * frame #0: 0x0000000104b81e14 Demo`-[ViewController touchesBegan:withEvent:](self=0x000000015ff04c90, _cmd="touchesBegan:withEvent:", touches=1 element, event=0x0000600000730cc0) at ViewController.m:32:1
    frame #1: 0x0000000184dbd96c UIKitCore`forwardTouchMethod + 316
    frame #2: 0x0000000184dcd65c UIKitCore`-[UIWindow _sendTouchesForEvent:] + 548
    frame #3: 0x0000000184dcf36c UIKitCore`-[UIWindow sendEvent:] + 4332
    frame #4: 0x0000000184da70fc UIKitCore`-[UIApplication sendEvent:] + 784
    frame #5: 0x0000000184e3559c UIKitCore`__dispatchPreprocessedEventFromEventQueue + 7720
    frame #6: 0x0000000184e37620 UIKitCore`__processEventQueue + 6764
    frame #7: 0x0000000184e2f540 UIKitCore`__eventFetcherSourceCallback + 184
    frame #8: 0x0000000180362234 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    frame #9: 0x0000000180362134 CoreFoundation`__CFRunLoopDoSource0 + 204
    frame #10: 0x00000001803614c4 CoreFoundation`__CFRunLoopDoSources0 + 256
    frame #11: 0x000000018035ba18 CoreFoundation`__CFRunLoopRun + 744
    frame #12: 0x000000018035b218 CoreFoundation`CFRunLoopRunSpecific + 572
    frame #13: 0x000000018c25f60c GraphicsServices`GSEventRunModal + 160
    frame #14: 0x0000000184d88a98 UIKitCore`-[UIApplication _run] + 992
    frame #15: 0x0000000184d8d634 UIKitCore`UIApplicationMain + 112
    frame #16: 0x0000000104b82080 Demo`main(argc=1, argv=0x000000016b27dc88) at main.m:21:12
    frame #17: 0x0000000104d9dcd8 dyld_sim`start_sim + 20
    frame #18: 0x0000000104f1108c dyld`start + 520
  thread #5, name = 'com.apple.uikit.eventfetch-thread'
    frame #0: 0x00000001cc055fcc libsystem_kernel.dylib`mach_msg_trap + 8
    frame #1: 0x00000001cc056430 libsystem_kernel.dylib`mach_msg + 72
    frame #2: 0x000000018036176c CoreFoundation`__CFRunLoopServiceMachPort + 368
    frame #3: 0x000000018035bb78 CoreFoundation`__CFRunLoopRun + 1096
    frame #4: 0x000000018035b218 CoreFoundation`CFRunLoopRunSpecific + 572
    frame #5: 0x0000000180827828 Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 232
    frame #6: 0x0000000180827ae0 Foundation`-[NSRunLoop(NSRunLoop) runUntilDate:] + 88
    frame #7: 0x0000000184e3f01c UIKitCore`-[UIEventFetcher threadMain] + 472
    frame #8: 0x0000000180851578 Foundation`__NSThread__start__ + 792
    frame #9: 0x00000001cc0b16c8 libsystem_pthread.dylib`_pthread_start + 116
  thread #9
    frame #0: 0x00000001cc057ce4 libsystem_kernel.dylib`__workq_kernreturn + 8
(lldb) 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 当手指轻触屏幕,整个系统像沉睡的生灵突然被惊醒,然后经历过腥风血雨的一段奇幻旅行,最终又归于沉寂。 整个iOS触摸...
    FengyunSky阅读 540评论 0 1
  • 在iOS开发中经常会涉及到触摸事件。本想自己总结一下,但是遇到了这篇文章,感觉总结的已经很到位,特此转载。作者:L...
    WQ_UESTC阅读 6,138评论 4 26
  • 在开发过程中,大家或多或少的都会碰到令人头疼的手势冲突问题,正好前两天碰到一个类似的bug,于是借着这个机会了解了...
    闫仕伟阅读 5,440评论 2 23
  • 本文主要讲解iOS触摸事件的一系列机制,涉及的问题大致包括: 触摸事件由触屏生成后如何传递到当前应用? 应用接收触...
    baihualinxin阅读 1,228评论 0 9
  • 好奇触摸事件是如何从屏幕转移到APP内的?困惑于Cell怎么突然不能点击了?纠结于如何实现这个奇葩响应需求?亦或是...
    Lotheve阅读 58,157评论 51 603