{"id":3969,"date":"2025-05-28T13:39:48","date_gmt":"2025-06-04T06:04:48","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3969"},"modified":"2025-06-04T13:39:48","modified_gmt":"2025-06-04T06:04:48","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8swift%e4%b8%ad%e7%9a%84%e8%bd%bb%e6%89%ab%e6%89%8b%e5%8a%bf%e8%af%86%e5%88%ab%e5%99%a8","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8swift%e4%b8%ad%e7%9a%84%e8%bd%bb%e6%89%ab%e6%89%8b%e5%8a%bf%e8%af%86%e5%88%ab%e5%99%a8\/","title":{"rendered":"\u5b8c\u5168\u638c\u63e1Swift\u4e2d\u7684\u8f7b\u626b\u624b\u52bf\u8bc6\u522b\u5668\uff1a\u4ece\u57fa\u7840\u5230\u5b9e\u6218"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Swift, UISwipeGestureRecognizer, \u8f7b\u626b\u624b\u52bf\u8bc6\u522b\u5668, iOS\u5f00\u53d1, \u624b\u52bf\u8bc6\u522b\"><\/p>\n<h1>\u5b8c\u5168\u638c\u63e1Swift\u4e2d\u7684\u8f7b\u626b\u624b\u52bf\u8bc6\u522b\u5668\uff1a\u4ece\u57fa\u7840\u5230\u5b9e\u6218<\/h1>\n<p>Swift\u662f\u4e00\u79cd\u73b0\u4ee3\u5316\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8eiOS\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u3002\u8f7b\u626b\u624b\u52bf\u8bc6\u522b\u5668\uff08UISwipeGestureRecognizer\uff09\u662fSwift\u4e2d\u4e00\u4e2a\u91cd\u8981\u7684\u5de5\u5177\uff0c\u5b83\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u65b9\u5f0f\u6765\u589e\u5f3a\u7528\u6237\u754c\u9762\u7684\u4ea4\u4e92\u6027\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u6709\u6548\u4f7f\u7528UISwipeGestureRecognizer\uff0c\u5305\u62ec\u521b\u5efa\u624b\u52bf\u8bc6\u522b\u5668\u3001\u8bbe\u7f6e\u624b\u52bf\u65b9\u5411\uff0c\u4ee5\u53ca\u76f8\u5173\u7684\u5b9e\u7528\u6280\u5de7\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528UISwipeGestureRecognizer\u521b\u5efa\u8f7b\u626b\u624b\u52bf\u8bc6\u522b\u5668<\/h2>\n<p>\u521b\u5efa\u4e00\u4e2a\u8f7b\u626b\u624b\u52bf\u8bc6\u522b\u5668\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b9e\u4f8b\u5316\u4e00\u4e2aUISwipeGestureRecognizer\u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u9700\u8981\u8bc6\u522b\u8f7b\u626b\u624b\u52bf\u7684\u89c6\u56fe\u4e2d\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u7684\u57fa\u672c\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre class=\"brush: python\">\nlet swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipeGesture))\nview.addGestureRecognizer(swipeGestureRecognizer)\n<\/pre>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u8f7b\u626b\u624b\u52bf\u8bc6\u522b\u5668\u5e76\u5c06\u5176\u7ed1\u5b9a\u5230\u89c6\u56fe\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5b9e\u73b0handleSwipeGesture\u65b9\u6cd5\uff0c\u4ee5\u5904\u7406\u7528\u6237\u7684\u8f7b\u626b\u52a8\u4f5c\uff1a<\/p>\n<pre class=\"brush: python\">\n@objc func handleSwipeGesture(gesture: UISwipeGestureRecognizer) {\n    switch gesture.direction {\n    case .right:\n        print(\"\u53f3\u6ed1\u624b\u52bf\u88ab\u8bc6\u522b\")\n    case .left:\n        print(\"\u5de6\u6ed1\u624b\u52bf\u88ab\u8bc6\u522b\")\n    case .up:\n        print(\"\u4e0a\u6ed1\u624b\u52bf\u88ab\u8bc6\u522b\")\n    case .down:\n        print(\"\u4e0b\u6ed1\u624b\u52bf\u88ab\u8bc6\u522b\")\n    default:\n        break\n    }\n}\n<\/pre>\n<h2>\u5982\u4f55\u8bbe\u7f6e\u8f7b\u626b\u624b\u52bf\u7684\u65b9\u5411<\/h2>\n<p>UISwipeGestureRecognizer\u9ed8\u8ba4\u53ea\u8bc6\u522b\u53f3\u6ed1\u624b\u52bf\u3002\u5982\u679c\u60a8\u5e0c\u671b\u8bc6\u522b\u5176\u4ed6\u65b9\u5411\u7684\u8f7b\u626b\u624b\u52bf\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u5176<span style=\"color: #ff0000; font-weight: bold;\">direction<\/span>\u5c5e\u6027\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u60f3\u8bc6\u522b\u5de6\u6ed1\u624b\u52bf\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre class=\"brush: python\">\nswipeGestureRecognizer.direction = .left\n<\/pre>\n<p>\u9664\u4e86<span style=\"color: #ff0000; font-weight: bold;\">.left<\/span>\uff0c\u60a8\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u4e3a<span style=\"color: #ff0000; font-weight: bold;\">.right<\/span>\u3001<span style=\"color: #ff0000; font-weight: bold;\">.up<\/span>\u548c<span style=\"color: #ff0000; font-weight: bold;\">.down<\/span>\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728Swift\u4e2d\u4f7f\u7528\u8f7b\u626b\u624b\u52bf\u8bc6\u522b\u5668\uff08UISwipeGestureRecognizer\uff09\uff0c\u5305\u62ec\u521b\u5efa\u624b\u52bf\u8bc6\u522b\u5668\u3001\u5904\u7406\u624b\u52bf\u4e8b\u4ef6\u548c\u8bbe\u7f6e\u624b\u52bf\u65b9\u5411\u3002\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u63d0\u5347iOS\u5e94\u7528\u7684\u7528\u6237\u4f53\u9a8c\uff0c\u589e\u5f3a\u4ea4\u4e92\u6027\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u7684Swift\u7f16\u7a0b\u4e4b\u65c5\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684\u8f7b\u626b\u624b\u52bf\u8bc6\u522b\u5668\uff0c\u5305\u62ec\u4f7f\u7528UISwipeGestureRecognizer\u7c7b\u5b9e\u73b0\u8f7b\u626b\u624b\u52bf\u8bc6\u522b\u5668\u3001\u8a2d\u7f6e\u8f7b\u626b\u65b9\u5411\u7b49\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","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-3969","post","type-post","status-publish","format-standard","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-121","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3969","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=3969"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3969\/revisions"}],"predecessor-version":[{"id":3970,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3969\/revisions\/3970"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}