{"id":7572,"date":"2025-05-30T12:39:02","date_gmt":"2025-06-05T05:38:02","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7572"},"modified":"2025-06-05T12:39:02","modified_gmt":"2025-06-05T05:38:02","slug":"https-badgameshow-com-steven-443","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-443\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Swift 4.2+ \u57f7\u884c UISwipeGestureRecognizer \u624b\u52e2\u64cd\u4f5c\uff1a2025 \u6700\u65b0\u6559\u5b78"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"swift, UISwipeGestureRecognizer, \u624b\u52e2\u64cd\u4f5c, iOS \u958b\u767c\"><\/p>\n<h2>\u4ec0\u9ebc\u662f UISwipeGestureRecognizer\uff1f<\/h2>\n<p>UISwipeGestureRecognizer \u662f iOS \u958b\u767c\u4e2d\u4e00\u500b\u975e\u5e38\u91cd\u8981\u7684\u529f\u80fd\uff0c\u80fd\u5920\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u5075\u6e2c\u4f7f\u7528\u8005\u7684\u6ed1\u52d5\u624b\u52e2\uff0c\u4f8b\u5982\u5411\u5de6\u6ed1\u3001\u5411\u53f3\u6ed1\u7b49\u3002\u9019\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u6839\u64da\u4f7f\u7528\u8005\u7684\u624b\u52e2\u4f86\u63a7\u5236 App \u7684\u884c\u70ba\uff0c\u63d0\u4f9b\u66f4\u4f73\u7684\u4f7f\u7528\u8005\u9ad4\u9a57\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 UISwipeGestureRecognizer<\/h2>\n<p>\u5728\u9019\u88e1\uff0c\u6211\u5011\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 UISwipeGestureRecognizer \u4f86\u5075\u6e2c\u624b\u52e2\u64cd\u4f5c\u3002<\/p>\n<h3>\u6b65\u9a5f 1\uff1a\u5efa\u7acb UISwipeGestureRecognizer \u7269\u4ef6<\/h3>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5728 ViewController \u4e2d\u5efa\u7acb\u4e00\u500b UISwipeGestureRecognizer \u7269\u4ef6\uff0c\u4e26\u6307\u5b9a\u5b83\u7684\u65b9\u5411\u5c6c\u6027\uff08direction\uff09\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nlet swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe))<br \/>\nswipeGestureRecognizer.direction = .right \/\/ \u53ef\u4ee5\u9078\u64c7 .left, .up, .down<br \/>\n&#8220;`<\/p>\n<h3>\u6b65\u9a5f 2\uff1a\u5c07\u624b\u52e2\u8b58\u5225\u5668\u6dfb\u52a0\u5230\u8996\u5716\u4e2d<\/h3>\n<p>\u63a5\u8457\uff0c\u6211\u5011\u9700\u8981\u5c07 UISwipeGestureRecognizer \u7269\u4ef6\u52a0\u5165\u5230 ViewController \u7684\u8996\u5716\u4e2d\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nview.addGestureRecognizer(swipeGestureRecognizer)<br \/>\n&#8220;`<\/p>\n<h3>\u6b65\u9a5f 3\uff1a\u5be6\u4f5c\u624b\u52e2\u8655\u7406\u65b9\u6cd5<\/h3>\n<p>\u6700\u5f8c\uff0c\u6211\u5011\u9700\u8981\u5be6\u4f5c handleSwipe \u65b9\u6cd5\uff0c\u4ee5\u4fbf\u5728\u4f7f\u7528\u8005\u5075\u6e2c\u5230 UISwipeGestureRecognizer \u624b\u52e2\u64cd\u4f5c\u6642\uff0c\u53ef\u4ee5\u57f7\u884c\u7279\u5b9a\u7684\u52d5\u4f5c\uff1a<\/p>\n<p>&#8220;`swift<br \/>\n@objc func handleSwipe() {<br \/>\n    \/\/ \u5728\u9019\u88e1\u5be6\u4f5c\u4f60\u60f3\u8981\u57f7\u884c\u7684\u52d5\u4f5c\uff0c\u4f8b\u5982\u986f\u793a\u63d0\u793a\u8a0a\u606f<br \/>\n    print(&#8220;\u624b\u52e2\u6ed1\u52d5\u88ab\u5075\u6e2c\u5230\uff01&#8221;)<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5982\u679c\u624b\u52e2\u64cd\u4f5c\u7121\u6cd5\u6b63\u5e38\u5075\u6e2c\uff0c\u8acb\u6aa2\u67e5\u4ee5\u4e0b\u5e7e\u9ede\uff1a<br \/>\n1. \u78ba\u4fdd\u624b\u52e2\u8b58\u5225\u5668\u5df2\u6b63\u78ba\u6dfb\u52a0\u5230\u8996\u5716\u4e2d\u3002<br \/>\n2. \u78ba\u4fdd ViewController \u7684\u8996\u5716\u662f\u53ef\u4e92\u52d5\u7684\uff0c\u4e26\u4e14\u6c92\u6709\u5176\u4ed6\u8996\u5716\u906e\u64cb\u3002<br \/>\n3. \u78ba\u4fdd\u624b\u52e2\u7684\u65b9\u5411\u5c6c\u6027\u6b63\u78ba\u8a2d\u7f6e\uff0c\u4e14\u7b26\u5408\u4f7f\u7528\u8005\u7684\u6ed1\u52d5\u65b9\u5411\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>UISwipeGestureRecognizer \u4e0d\u50c5\u53ef\u4ee5\u7528\u65bc\u6ed1\u52d5\u624b\u52e2\uff0c\u9084\u53ef\u4ee5\u8207\u5176\u4ed6\u624b\u52e2\u8b58\u5225\u5668\u7d50\u5408\u4f7f\u7528\uff0c\u5be6\u73fe\u66f4\u8907\u96dc\u7684\u624b\u52e2\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5c07 UISwipeGestureRecognizer \u8207 UITapGestureRecognizer \u7d50\u5408\uff0c\u4f86\u5075\u6e2c\u6ed1\u52d5\u5f8c\u7684\u9ede\u64ca\u884c\u70ba\uff0c\u9032\u4e00\u6b65\u8c50\u5bcc\u4f7f\u7528\u8005\u7684\u4e92\u52d5\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u624b\u52e2\u64cd\u4f5c-UISwipeGestureRecognizer_1675477569.7859042.webp\" alt=\"Swift \u624b\u52e2\u64cd\u4f5c UISwipeGestureRecognizer\" title=\"Swift \u624b\u52e2\u64cd\u4f5c, UISwipeGestureRecognizer, \u624b\u52e2\u64cd\u4f5c, Swift, \u624b\u52e2\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: UISwipeGestureRecognizer \u53ef\u4ee5\u5075\u6e2c\u54ea\u4e9b\u624b\u52e2\u65b9\u5411\uff1f<\/h3>\n<p>A1: UISwipeGestureRecognizer \u53ef\u4ee5\u5075\u6e2c\u56db\u500b\u65b9\u5411\u7684\u6ed1\u52d5\u624b\u52e2\uff1a\u5411\u5de6\u3001\u5411\u53f3\u3001\u5411\u4e0a\u548c\u5411\u4e0b\u3002\u65b9\u5411\u53ef\u4ee5\u901a\u904e direction \u5c6c\u6027\u9032\u884c\u8a2d\u7f6e\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u540c\u6642\u5075\u6e2c\u591a\u500b\u624b\u52e2\uff1f<\/h3>\n<p>A2: \u4f60\u53ef\u4ee5\u70ba\u6bcf\u500b\u9700\u8981\u5075\u6e2c\u7684\u624b\u52e2\u5275\u5efa\u4e0d\u540c\u7684 UISwipeGestureRecognizer \u7269\u4ef6\uff0c\u4e26\u5206\u5225\u6dfb\u52a0\u5230\u8996\u5716\u4e2d\uff0c\u7136\u5f8c\u5be6\u4f5c\u76f8\u61c9\u7684\u8655\u7406\u65b9\u6cd5\u3002<\/p>\n<h3>Q3: UISwipeGestureRecognizer \u662f\u5426\u53ef\u4ee5\u8207\u5176\u4ed6\u624b\u52e2\u8b58\u5225\u5668\u4e00\u8d77\u4f7f\u7528\uff1f<\/h3>\n<p>A3: \u662f\u7684\uff0c\u4f60\u53ef\u4ee5\u5c07 UISwipeGestureRecognizer \u8207\u5176\u4ed6\u624b\u52e2\u8b58\u5225\u5668\u5982 UITapGestureRecognizer \u6216 UIRotationGestureRecognizer \u7d50\u5408\u4f7f\u7528\uff0c\u4ee5\u5be6\u73fe\u66f4\u8c50\u5bcc\u7684\u624b\u52e2\u4e92\u52d5\u9ad4\u9a57\u3002<\/p>\n<p>&#8212;<\/p>\n<p>\u9019\u6a23\u7684\u512a\u5316\u4e0d\u50c5\u88dc\u5145\u4e86\u5167\u5bb9\u7684\u5b8c\u6574\u6027\uff0c\u9084\u5f37\u8abf\u4e86\u6700\u65b0\u7684\u8a9e\u6cd5\u548c\u4f7f\u7528\u6700\u4f73\u5be6\u8e10\uff0c\u4e26\u7b26\u5408 SEO \u7684\u8981\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981(Description):\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684UISwipeGestureRecognizer\u624b\u52e2\u64cd\u4f5c\uff0c\u8b93\u4f60\u7684App\u66f4\u52a0\u6709\u8da3\uff0c\u66f4\u52a0\u65b9\u4fbf\u4f7f\u7528\u8005\u64cd\u4f5c\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684UISwipeGestureRecognizer\u624b\u52e2\u64cd\u4f5c\uff0c\u4ee5\u53ca\u5982\u4f55\u8a2d\u7f6e\u624b\u52e2\u64cd\u4f5c\u7684\u53c3\u6578\u3002<\/p>\n","protected":false},"author":1,"featured_media":7569,"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-7572","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-\u624b\u52e2\u64cd\u4f5c-UISwipeGestureRecognizer_1675477569.7859042.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Y8","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7572","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=7572"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7572\/revisions"}],"predecessor-version":[{"id":13249,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7572\/revisions\/13249"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7569"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}