{"id":7012,"date":"2025-06-03T14:05:30","date_gmt":"2025-06-05T06:49:29","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7012"},"modified":"2025-06-05T14:05:30","modified_gmt":"2025-06-05T06:49:29","slug":"https-badgameshow-com-steven-182","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-182\/","title":{"rendered":"Swift \u89f8\u63a7\u4e8b\u4ef6\u8655\u7406\u6559\u5b78\uff1a2025 \u6700\u65b0\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, \u89f8\u63a7\u4e8b\u4ef6, \u53cd\u61c9\u89f8\u78b0\u4e8b\u4ef6, iOS \u958b\u767c, UIGestureRecognizer\"><\/p>\n<h2>\u4ec0\u9ebc\u662f Swift \u89f8\u63a7\u4e8b\u4ef6\u8655\u7406\uff1f<\/h2>\n<p>Swift \u89f8\u63a7\u4e8b\u4ef6\u8655\u7406\u662f iOS \u958b\u767c\u4e2d\u81f3\u95dc\u91cd\u8981\u7684\u6280\u8853\uff0c\u80fd\u8b93\u958b\u767c\u8005\u6709\u6548\u63a7\u5236\u7528\u6236\u7684\u89f8\u63a7\u884c\u70ba\uff0c\u5305\u62ec\u6ed1\u52d5\u3001\u9ede\u64ca\u3001\u62d6\u62fd\u7b49\u3002\u7576\u7528\u6236\u5728\u87a2\u5e55\u4e0a\u89f8\u63a7\u6642\uff0ciOS \u7cfb\u7d71\u6703\u6aa2\u6e2c\u5230\u8a72\u89f8\u63a7\u4e8b\u4ef6\uff0c\u4e26\u5c07\u5176\u50b3\u905e\u7d66\u61c9\u7528\u7a0b\u5e8f\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9019\u4e9b\u4e8b\u4ef6\u9032\u884c\u76f8\u61c9\u7684\u8655\u7406\u3002<\/p>\n<h2>\u5982\u4f55\u5728 Swift \u4e2d\u5be6\u73fe\u89f8\u63a7\u4e8b\u4ef6\u8655\u7406\uff1f<\/h2>\n<p>\u5728 Swift \u4e2d\u5be6\u73fe\u89f8\u63a7\u4e8b\u4ef6\u8655\u7406\u9700\u8981\u4f7f\u7528 <strong>UITouch<\/strong>\u3001<strong>UIView<\/strong> \u548c <strong>UIGestureRecognizer<\/strong>\u3002\u4ee5\u4e0b\u662f\u8a73\u7d30\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3>\u6b65\u9a5f\u4e00\uff1a\u5efa\u7acb UIView \u7269\u4ef6<\/h3>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5efa\u7acb\u4e00\u500b <strong>UIView<\/strong> \u7269\u4ef6\u4f86\u63a5\u6536\u89f8\u63a7\u4e8b\u4ef6\u3002<\/p>\n<pre><code class=\"language-swift line-numbers\">let touchableView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))<\/code><\/pre>\n<h3>\u6b65\u9a5f\u4e8c\uff1a\u8a2d\u7f6e UIGestureRecognizer<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u8a2d\u7f6e\u4e00\u500b\u624b\u52e2\u8fa8\u8b58\u5668\u4f86\u76e3\u807d\u89f8\u63a7\u4e8b\u4ef6\u3002\u9019\u88e1\u4ee5 <strong>UITapGestureRecognizer<\/strong> \u70ba\u4f8b\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))<\/code><\/pre>\n<h3>\u6b65\u9a5f\u4e09\uff1a\u8655\u7406\u89f8\u63a7\u4e8b\u4ef6<\/h3>\n<p>\u6211\u5011\u9700\u8981\u5be6\u4f5c\u4e00\u500b\u65b9\u6cd5\u4f86\u8655\u7406\u89f8\u63a7\u4e8b\u4ef6\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">@objc func handleTap(_ sender: UITapGestureRecognizer) {\n    let location = sender.location(in: touchableView)\n    print(\"Tapped at location: \\(location)\")\n}<\/code><\/pre>\n<h3>\u6b65\u9a5f\u56db\uff1a\u5c07\u624b\u52e2\u8fa8\u8b58\u5668\u6dfb\u52a0\u5230 UIView<\/h3>\n<p>\u6700\u5f8c\uff0c\u5c07\u624b\u52e2\u8fa8\u8b58\u5668\u6dfb\u52a0\u5230 <strong>UIView<\/strong> \u4e2d\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">touchableView.addGestureRecognizer(tapGestureRecognizer)<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u5be6\u4f5c\u89f8\u63a7\u4e8b\u4ef6\u8655\u7406\u6642\uff0c\u60a8\u53ef\u80fd\u6703\u9047\u5230\u4ee5\u4e0b\u5e38\u898b\u554f\u984c\uff1a<\/p>\n<ul>\n<li><strong>\u624b\u52e2\u672a\u88ab\u89f8\u767c\uff1a<\/strong>\u78ba\u4fdd UIView \u7684 userInteractionEnabled \u5c6c\u6027\u8a2d\u70ba true\u3002<\/li>\n<li><strong>\u89f8\u63a7\u4f4d\u7f6e\u4e0d\u6b63\u78ba\uff1a<\/strong>\u6aa2\u67e5\u624b\u52e2\u8fa8\u8b58\u5668\u7684\u5ea7\u6a19\u4f4d\u7f6e\u662f\u5426\u6b63\u78ba\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u64f4\u5c55\u89f8\u63a7\u4e8b\u4ef6\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u5be6\u73fe\u591a\u91cd\u624b\u52e2\u8b58\u5225\u3001\u62d6\u62fd\u64cd\u4f5c\u7b49\u3002\u9019\u53ef\u4ee5\u900f\u904e\u7d50\u5408\u4e0d\u540c\u7684\u624b\u52e2\u8fa8\u8b58\u5668\u4f86\u9054\u6210\u3002<\/p>\n<h2>\u7d50\u8a9e<\/h2>\n<p>\u4ee5\u4e0a\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Swift \u4e2d\u5be6\u73fe\u89f8\u63a7\u4e8b\u4ef6\u8655\u7406\u7684\u57fa\u672c\u6b65\u9a5f\u3002\u900f\u904e\u9019\u4e9b\u6280\u8853\uff0c\u958b\u767c\u8005\u80fd\u5920\u63d0\u5347 App \u7684\u7528\u6236\u4ea4\u4e92\u9ad4\u9a57\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<ul>\n<li><strong>Q: \u5982\u4f55\u8655\u7406\u591a\u91cd\u624b\u52e2\uff1f<\/strong><br \/>A: \u60a8\u53ef\u4ee5\u540c\u6642\u4f7f\u7528\u591a\u500b UIGestureRecognizer\uff0c\u4e26\u5728\u5176 delegate \u65b9\u6cd5\u4e2d\u5224\u65b7\u4f55\u6642\u89f8\u767c\u3002<\/li>\n<li><strong>Q: \u5982\u4f55\u53d6\u6d88\u624b\u52e2\u8b58\u5225\uff1f<\/strong><br \/>A: \u60a8\u53ef\u4ee5\u8abf\u7528 <code>removeGestureRecognizer<\/code> \u65b9\u6cd5\u4f86\u79fb\u9664\u624b\u52e2\u8fa8\u8b58\u5668\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u89f8\u63a7\u4e8b\u4ef6-\u53cd\u61c9\u89f8\u78b0\u4e8b\u4ef6-\ud83d\udcab_1675400573.317915.webp\" alt=\"Swift \u89f8\u63a7\u4e8b\u4ef6 \u53cd\u61c9\u89f8\u78b0\u4e8b\u4ef6 \ud83d\udcab\" title=\"Swift \u89f8\u63a7\u4e8b\u4ef6\u3001\u53cd\u61c9\u89f8\u78b0\u4e8b\u4ef6\u3001methods() \u51fd\u6578\u3001iOS \u88dd\u7f6e\u3001App\" width=\"1200\" height=\"628\"\/><br \/>\n&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2Swift\u4e2d\u89f8\u63a7\u4e8b\u4ef6\u53ca\u53cd\u61c9\u89f8\u78b0\u4e8b\u4ef6\uff0c\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684methods()\u51fd\u6578\uff0c\u4ee5\u53ca\u5982\u4f55\u61c9\u7528\u5728iOS\u88dd\u7f6e\u4e0a\uff0c\u8b93\u4f60\u7684App\u66f4\u52a0\u5b8c\u5584\u3002<\/p>\n","protected":false},"author":1,"featured_media":7011,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-7012","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u89f8\u63a7\u4e8b\u4ef6-\u53cd\u61c9\u89f8\u78b0\u4e8b\u4ef6-\ud83d\udcab_1675400573.317915.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1P6","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=7012"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7012\/revisions"}],"predecessor-version":[{"id":13304,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7012\/revisions\/13304"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7011"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}