{"id":42439,"date":"2023-12-11T14:56:34","date_gmt":"2023-12-11T06:56:34","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=42439"},"modified":"2023-12-11T14:56:34","modified_gmt":"2023-12-11T06:56:34","slug":"ios%e9%87%8c%e4%bb%80%e4%b9%88%e6%98%af%e5%93%8d%e5%ba%94%e9%93%be%ef%bc%8c%e5%ae%83%e6%98%af%e6%80%8e%e4%b9%88%e5%b7%a5%e4%bd%9c%e7%9a%84%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/ios%e9%87%8c%e4%bb%80%e4%b9%88%e6%98%af%e5%93%8d%e5%ba%94%e9%93%be%ef%bc%8c%e5%ae%83%e6%98%af%e6%80%8e%e4%b9%88%e5%b7%a5%e4%bd%9c%e7%9a%84%ef%bc%9f\/","title":{"rendered":"iOS\u91cc\u4ec0\u4e48\u662f\u54cd\u5e94\u94fe\uff0c\u5b83\u662f\u600e\u4e48\u5de5\u4f5c\u7684\uff1f"},"content":{"rendered":"<p>&#8220;`&#8221;<\/p>\n<blockquote><p>iOS\u91cc\u4ec0\u4e48\u662f\u54cd\u5e94\u94fe\uff0c\u5b83\u662f\u600e\u4e48\u5de5\u4f5c\u7684\uff1f\n<\/p><\/blockquote>\n<p>\u7b2c\u4e00\u53cd\u5e94\u5c31\u662f\uff0c\u54cd\u5e94\u94fe\u5c31\u662f\u54cd\u5e94\u94fe\u554a\uff0c\u7531\u4e00\u4e32UIResponder\u5bf9\u8c61\u94fe\u63a5\uff0c\u6536\u5230\u54cd\u5e94\u4e8b\u4ef6\u65f6\u7531\u4e0a\u5f80\u4e0b\u4f20\u9012\uff0c\u76f4\u5230\u80fd\u54cd\u5e94\u4e8b\u4ef6\u4e3a\u6b62\u3002<\/p>\n<p>\u4f46\u5176\u4e2d\u5374\u5927\u6709\u6587\u7ae0&#8230;<\/p>\n<h4>1.\u7531\u4e00\u4e32UIResponder\u5bf9\u8c61\u94fe\u63a5 \uff1f<\/h4>\n<p>\u6211\u4eec\u77e5\u9053UIResponder\u7c7b\u91cc\u6709\u4e2a\u5c5e\u6027\uff1a<\/p>\n<pre><code class=\"\"language-objectivec\"\" lang=\"\"objectivec\"\">@property(nonatomic, readonly, nullable) UIResponder *nextResponder;\n<\/code><\/pre>\n<p>\u5982\u679c\u6211\u4eec\u5bf9\u54cd\u5e94\u94fe\u539f\u7406\u4e0d\u6e05\u695a\u7684\u8bdd\uff0c\u4f1a\u5f88\u5bb9\u6613\u7684\u8ba4\u4e3a\uff0c\u8fd9\u6761\u94fe\u662f\u7531 nextResponder \u6307\u9488\u8fde\u63a5\u8d77\u6765\u7684\uff0c\u5728\u5bfb\u627e\u54cd\u5e94\u8005\u7684\u65f6\u5019\u662f\u987a\u7740\u8fd9\u4e2a\u6307\u9488\u627e\u4e0b\u53bb\u76f4\u5230\u627e\u5230\u54cd\u5e94\u8005\u4e3a\u6b62\u7684\uff0c\u4f46\u8fd9\u662f<strong>\u9519\u8bef<\/strong>\u7684\u8ba4\u4e3a\u3002<br \/>\n \u4e3e\u4e2a\u4f8b\u5b50\uff1a<br \/>\n \u73b0\u5728\u6211\u4eec\u6709\u8fd9\u6837\u4e00\u4e2a\u573a\u666f\uff1a<\/p>\n<p><img decoding=\"async\" alt=\"\"img\"\" referrerpolicy=\"\"no-referrer\"\" src=\"\"https:\/\/\/\/upload-images.jianshu.io\/upload_images\/2909238-115ea3fec18c40ef.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/750\/format\/webp\"\"><\/p>\n<p>E0B0C758-8B7D-4B6A-85F3-72F3A174DCEA.png<\/p>\n<p>AppDelegate\u4e0a\u7684Window\u4e0a\u6709\u4e00\u4e2aUIViewController *ViewController,<br \/>\n \u7136\u540e\u5728ViewController.view \u4e0a\u6309\u987a\u5e8f\u6dfb\u52a0viewA\u548cviewB\uff0cviewB\u7a0d\u5fae\u8986\u76d6viewA\u4e00\u90e8\u5206\u7528\u6765\u6d4b\u8bd5\uff0c<br \/>\n \u7ed9viewA\uff0cviewB \u5206\u522b\u6dfb\u52a0\u70b9\u51fb\u624b\u52bftapA \u548c tapB\uff0c\u7136\u540e\u628aviewB.userInteractionEnabled = NO\uff0c\u8ba9viewB\u4e0d\u80fd\u54cd\u5e94\u70b9\u51fb\u3002<\/p>\n<p><strong>\u7136\u540e\u6211\u4eec\u70b9\u51fb\u91cd\u590d\u7684\u90a3\u5757\u533a\u57df\uff0c\u4f1a\u53d1\u73b0viewA\u54cd\u5e94\u4e86tap\u624b\u52bf\uff0c\u6267\u884c\u4e86tapA\u7684\u4e8b\u4ef6\u3002<br \/>\n \u6211\u4eec\u77e5\u9053viewB\u8bbe\u7f6e\u4e86viewB.userInteractionEnabled = NO\uff0c\u4e0d\u54cd\u5e94tap\u624b\u52bf\u662f\u6b63\u5e38\u7684\uff0c\u4f46\u600e\u4e48\u4f1a\u900f\u8fc7viewB\uff0cviewA\u54cd\u5e94\u4e86\u624b\u52bf\uff1f<\/strong><\/p>\n<p>\u6211\u4eec\u77e5\u9053nextResponder\u6307\u9488\u6307\u5411\u7684\u89c4\u5219\uff1a<\/p>\n<blockquote><p>&nbsp;\n<\/p><\/blockquote>\n<ul>\n<li>UIView<\/li>\n<li>\u5982\u679c view \u662f\u4e00\u4e2a view controller \u7684 root view\uff0cnextResponder \u662f\u8fd9\u4e2a view controller.<\/li>\n<li>\u5982\u679c view \u4e0d\u662f view controller \u7684 root view\uff0cnextResponder \u5219\u662f\u8fd9\u4e2a view \u7684 superview<\/li>\n<li>UIViewController<\/li>\n<li>\u5982\u679c view controller \u7684 view \u662f window \u7684 root view, view controller \u7684 nextResponder \u662f\u8fd9\u4e2a window<\/li>\n<li>\u5982\u679c view controller \u662f\u88ab\u5176\u4ed6 view controller presented\u8c03\u8d77\u6765\u7684\uff0c\u90a3\u4e48 view controller \u7684 nextResponder \u5c31\u662f\u53d1\u8d77\u8c03\u8d77\u7684\u90a3\u4e2a view controller<\/li>\n<li>UIWindow<\/li>\n<li>window \u7684 nextResponder \u662f UIApplication \u5bf9\u8c61.<\/li>\n<li>UIApplication<\/li>\n<li>UIApplication \u5bf9\u8c61\u7684 nextResponder \u662f app delegate\uff0c \u4f46\u662f app delegate \u5fc5\u987b\u662f UIResponder \u5bf9\u8c61\uff0c\u5e76\u4e14\u4e0d\u80fd\u4f7f view \uff0cview controller \u6216  UIApplication \u5bf9\u8c61\u4ed6\u672c\u8eab.<\/li>\n<\/ul>\n<p>\u90a3\u4e48\u4e0a\u8ff0\u60c5\u51b5\u4e0b\uff0cviewB\u6240\u5728\u7684\u54cd\u5e94\u8005\u94fe\u5e94\u8be5\u662f\uff1a<br \/>\n viewB -&gt; ViewController.view -&gt; ViewController -&gt; Window -&gt; Application<br \/>\n \u8fd9\u79cd\u60c5\u51b5\u4e0b\u600e\u4e48\u4e5f\u8f6e\u4e0d\u5230viewA\u53bb\u54cd\u5e94\u554a\u3002<\/p>\n<p><strong>\u6240\u4ee5\uff0c\u5f53\u6709\u4e8b\u4ef6\u9700\u8981\u54cd\u5e94\u65f6\uff0cnextResponder \u5e76\u4e0d\u662f\u94fe\u63a5\u54cd\u5e94\u94fe\u7684\u90a3\u6839\u7ef3\u5b50\uff0c\u54cd\u5e94\u94fe\u7684\u5de5\u4f5c\u65b9\u5f0f\u53e6\u6709\u522b\u7684\u65b9\u5f0f<\/strong><\/p>\n<h4>2. \u90a3\u4e48\u54cd\u5e94\u94fe\u662f\u5982\u4f55\u5de5\u4f5c\uff0c\u6b63\u786e\u627e\u5230\u5e94\u8be5\u54cd\u5e94\u8be5\u4e8b\u4ef6\u7684\u54cd\u5e94\u8005\u7684\uff1f<\/h4>\n<blockquote><p>UIKit\u4f7f\u7528\u57fa\u4e8e\u89c6\u56fe\u7684hit-testing\u6765\u786e\u5b9atouch\u4e8b\u4ef6\u53d1\u751f\u7684\u4f4d\u7f6e\u3002\u5177\u4f53\u89e3\u91ca\u5c31\u662f\uff0cUIKit\u5c06touch\u7684\u4f4d\u7f6e\u548c\u89c6\u56fe\u5c42\u7ea7\u4e2d\u7684view\u7684\u8fb9\u754c\u8fdb\u884c\u4e86\u6bd4\u8f83\uff0cUIView\u7684\u65b9\u6cd5 hitTest:withEvent: \u5728\u89c6\u56fe\u5c42\u7ea7\u4e2d\u8fdb\u884c\uff0c\u5bfb\u627e\u5305\u542b\u6307\u5b9atouch\u7684\u6700\u6df1\u5b50\u89c6\u56fe\u3002\u8fd9\u4e2a\u89c6\u56fe\u6210\u4e3atouch\u4e8b\u4ef6\u7684\u7b2c\u4e00\u4e2a\u54cd\u5e94\u8005\u3002\n<\/p><\/blockquote>\n<p>\u8bf4\u767d\u4e86\u5c31\u662f\uff0c\u5f53\u6709touch\u4e8b\u4ef6\u6765\u7684\u65f6\u5019\uff0c\u4f1a\u4ece\u6700\u4e0b\u9762\u7684\u89c6\u56fe\u5f00\u59cb\u6267\u884c hitTest:withEvent: \uff0c\u5982\u679c\u7b26\u5408\u6210\u4e3a\u54cd\u5e94\u8005\u7684\u6761\u4ef6\uff0c\u5c31\u4f1a\u7ee7\u7eed\u904d\u5386\u5b83\u7684 subviews \u7ee7\u7eed\u6267\u884c hitTest:withEvent: \uff0c\u76f4\u5230\u627e\u5230\u6700\u5408\u9002\u7684view\u6210\u4e3a\u54cd\u5e94\u8005\u3002<\/p>\n<p><strong>\u8fd9\u91cc\u8981\u6ce8\u610f\u51e0\u4e2a\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li>\u7b26\u5408\u54cd\u5e94\u8005\u7684\u6761\u4ef6\u5305\u62ec<\/li>\n<li>touch\u4e8b\u4ef6\u7684\u4f4d\u7f6e\u5728\u54cd\u5e94\u8005\u533a\u57df\u5185<\/li>\n<li>\u54cd\u5e94\u8005 hidden \u5c5e\u6027\u4e0d\u4e3a YES<\/li>\n<li>\u54cd\u5e94\u8005 \u900f\u660e\u5ea6 \u4e0d\u662f 0<\/li>\n<li>\u54cd\u5e94\u8005 userInteractionEnabled \u4e0d\u4e3a NO<\/li>\n<li>\u904d\u5386 subview \u65f6\uff0c\u662f\u4ece\u4e0a\u5f80\u4e0b\u987a\u5e8f\u904d\u5386\u7684\uff0c\u5373 view.subviews \u7684 lastObject \u5230 firstObject \u7684\u987a\u5e8f\uff0c\u627e\u5230\u5408\u9002\u7684\u54cd\u5e94\u8005view\uff0c\u5373\u505c\u6b62\u904d\u5386.<\/li>\n<\/ul>\n<p>\u6240\u4ee5\u518d\u56de\u770b\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u5f53\u6211\u4eec\u70b9\u51fb\u4e2d\u95f4\u7684\u91cd\u590d\u533a\u57df\u65f6\uff0c\u6d41\u7a0b\u5176\u5b9e\u662f\u8fd9\u6837\uff1a<\/p>\n<ul>\n<li>AppDelegate \u7684 window \u6536\u5230\u4e8b\u4ef6\uff0c\u5e76\u5f00\u59cb\u6267\u884c hitTest:withEvent: \uff0c\u53d1\u73b0\u7b26\u5408\u8981\u6c42\uff0c\u5f00\u59cb\u904d\u5386\u5b50view.<\/li>\n<li>window \u4e0a\u53ea\u6709 viewcontroller.view ,\u6240\u4ee5viewcontroller.view \u5f00\u59cb\u6267\u884c hitTest:withEvent: \uff0c\u53d1\u73b0\u7b26\u5408\u8981\u6c42\uff0c\u5f00\u59cb\u904d\u5386\u5b50view.<\/li>\n<li>viewcontroller.view \u6709\u4e24\u4e2a\u5b50view\uff0c viewA \u548c viewB \uff0c\u4f46\u662fviewB \u5728 viewA \u4e0a\u8fb9\uff0c\u6240\u4ee5\u5148 viewB \u6267\u884c hitTest:withEvent: \uff0c\u7ed3\u679c\u53d1\u73b0viewB \u4e0d\u7b26\u5408\u8981\u6c42\uff0c\u56e0\u4e3aviewB \u7684 userInteractionEnabled \u4e3a NO.<\/li>\n<li>\u63a5\u4e0b\u6765 viewA \u6267\u884c hitTest:withEvent: \uff0c\u53d1\u73b0\u7b26\u5408\u6761\u4ef6\uff0c\u5e76\u4e14viewA \u4e5f\u6ca1\u6709\u5b50view\u53ef\u53bb\u904d\u5386\uff0c\u4e8e\u662f\u8fd4\u56deviewA.<\/li>\n<li>viewA\u6210\u4e86\u6700\u7ec8\u4e8b\u4ef6\u7684\u54cd\u5e94\u8005.<\/li>\n<\/ul>\n<p>\u8fd9\u6837\u5c31\u5b8c\u7f8e\u89e3\u91ca\u4e86\uff0c\u6700\u5f00\u59cb\u4f8b\u5b50\u7684\u54cd\u5e94\u72b6\u51b5.<\/p>\n<p>\u90a3\u4e48\u5982\u679c viewB \u7684 userInteractionEnabled \u5c5e\u6027\u4e3aYES\u7684\u8bdd\uff0c\u662f\u600e\u4e48\u6837\u7684\u5462\uff1f<\/p>\n<p>\u5982\u679c viewB \u7684 userInteractionEnabled \u5c5e\u6027\u4e3aYES\uff0c\u4e0a\u9762\u6d41\u7a0b\u7684\u7b2c\u4e09\u90e8\u5c31\u4f1a\u53d1\u73b0viewB\u662f\u7b26\u5408\u8981\u6c42\u7684\uff0c\u800c\u76f4\u63a5\u8fd4\u56deviewB\u4f5c\u4e3a\u6700\u7ec8\u54cd\u5e94\u8005\uff0c\u4e2d\u65ad\u5b50view\u7684\u904d\u5386\uff0cviewA\u90fd\u4e0d\u4f1a\u88ab\u904d\u5386\u5230\u4e86.<\/p>\n<p>\u8fd9\u5c31\u662f\u54cd\u5e94\u94fe\u76f8\u5173\u7684\u70b9\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u4e0d\u5bf9\u7684\u8bf7\u7559\u8a00\u63d0\u793a\uff0c\u7136\u540e\u6709\u4ec0\u4e48\u522b\u7684\u9700\u8981\u8865\u5145\u7684\u6211\u4f1a\u53ca\u65f6\u8865\u5145~<\/p>\n<p>&nbsp;<\/p>\n<pre><code>            \"```\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; iOS\u91cc\u4ec0\u4e48\u662f\u54cd\u5e94\u94fe\uff0c\u5b83\u662f\u600e\u4e48\u5de5\u4f5c\u7684\uff1f \u7b2c\u4e00\u53cd\u5e94\u5c31\u662f\uff0c\u54cd\u5e94\u94fe\u5c31\u662f\u54cd\u5e94\u94fe\u554a\uff0c\u7531\u4e00 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-42439","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/42439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=42439"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/42439\/revisions"}],"predecessor-version":[{"id":42440,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/42439\/revisions\/42440"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=42439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=42439"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=42439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}