{"id":3967,"date":"2025-06-04T11:38:54","date_gmt":"2025-06-05T03:50:54","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3967"},"modified":"2025-06-05T11:38:54","modified_gmt":"2025-06-05T03:50:54","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%e6%97%8b%e8%bd%ac%e6%89%8b%e5%8b%a2%e8%ad%98%e5%88%a5%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%e6%97%8b%e8%bd%ac%e6%89%8b%e5%8b%a2%e8%ad%98%e5%88%a5%e5%99%a8\/","title":{"rendered":"2025 \u6700\u65b0\u7248 Swift \u7a0b\u5f0f\u6559\u5b78\uff1a\u4f7f\u7528 UIRotationGestureRecognizer \u5be6\u73fe\u65cb\u8f49\u624b\u52e2\u8b58\u5225\u5668"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Swift, UIRotationGestureRecognizer, \u65cb\u8f6c\u624b\u52bf\u8bc6\u522b\u5668, \u624b\u52bf\u8bc6\u522b, iOS \u5f00\u53d1\"><\/p>\n<h1>2025 \u6700\u65b0\u7248 Swift \u7a0b\u5f0f\u6559\u5b78\uff1a\u4f7f\u7528 UIRotationGestureRecognizer \u5be6\u73fe\u65cb\u8f49\u624b\u52e2\u8b58\u5225\u5668<\/h1>\n<p>Swift \u662f\u4e00\u79cd\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e7f\u6cdb\u7528\u4e8e iOS \u548c macOS \u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u3002\u672c\u6587\u5c07\u6df1\u5165\u4ecb\u7d39\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 UIRotationGestureRecognizer \u7c7b\u4f86\u5be6\u73fe\u65cb\u8f49\u624b\u52e2\u8b58\u5225\u5668\uff0c\u4e26\u5c55\u793a\u6700\u65b0\u7684\u8a9e\u6cd5\u53ca\u6700\u4f73\u5be6\u8e10\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u8f15\u9b06\u6dfb\u52a0\u624b\u52e2\u8b58\u5225\u529f\u80fd\u3002<\/p>\n<h2>\u4f7f\u7528 UIRotationGestureRecognizer \u985e\u5be6\u73fe\u65cb\u8f49\u624b\u52e2\u8b58\u5225\u5668<\/h2>\n<p>\u8981\u5be6\u73fe\u65cb\u8f49\u624b\u52e2\u8b58\u5225\u5668\uff0c\u9996\u8981\u6b65\u9a5f\u662f\u5275\u5efa\u4e00\u500b UIRotationGestureRecognizer \u5c0d\u8c61\uff0c\u4e26\u5c07\u5176\u6dfb\u52a0\u5230\u9700\u8981\u8b58\u5225\u65cb\u8f49\u624b\u52e2\u7684\u8996\u5716\u4e0a\u3002\u4ee5\u4e0b\u662f\u5177\u9ad4\u7684\u5be6\u4f5c\u6b65\u9a5f\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nlet rotationGestureRecognizer = UIRotationGestureRecognizer(target: self, action: #selector(handleRotation))<br \/>\nview.addGestureRecognizer(rotationGestureRecognizer)<br \/>\n&#8220;`<\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b UIRotationGestureRecognizer \u5c0d\u8c61\uff0c\u4e26\u5c07\u5176\u9644\u52a0\u5230\u8996\u5716\u4e0a\u3002\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5be6\u73fe `handleRotation` \u65b9\u6cd5\uff0c\u4ee5\u4fbf\u5728\u6aa2\u6e2c\u5230\u65cb\u8f49\u624b\u52e2\u6642\u57f7\u884c\u76f8\u61c9\u7684\u64cd\u4f5c\u3002<\/p>\n<p>&#8220;`swift<br \/>\n@objc func handleRotation(sender: UIRotationGestureRecognizer) {<br \/>\n    \/\/ \u5728\u9019\u88e1\u8655\u7406\u65cb\u8f49\u624b\u52e2<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2>\u7372\u53d6\u65cb\u8f49\u624b\u52e2\u7684\u65cb\u8f49\u89d2\u5ea6<\/h2>\n<p>\u7576\u6aa2\u6e2c\u5230\u65cb\u8f49\u624b\u52e2\u6642\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 `sender.rotation` \u5c6c\u6027\u4f86\u7372\u53d6\u65cb\u8f49\u624b\u52e2\u7684\u65cb\u8f49\u89d2\u5ea6\u3002\u4ee5\u4e0b\u662f\u5b8c\u6574\u7684\u4ee3\u78bc\u793a\u4f8b\uff1a<\/p>\n<p>&#8220;`swift<br \/>\n@objc func handleRotation(sender: UIRotationGestureRecognizer) {<br \/>\n    let rotation = sender.rotation<br \/>\n    print(&#8220;\u5f53\u524d\u65cb\u8f6c\u89d2\u5ea6: \\(rotation) \u5f27\u5ea6&#8221;)<\/p>\n<p>    \/\/ \u6839\u64da\u65cb\u8f49\u89d2\u5ea6\u57f7\u884c\u5f8c\u7e8c\u64cd\u4f5c\uff0c\u4f8b\u5982\u65cb\u8f49\u8996\u5716<br \/>\n    if let viewToRotate = sender.view {<br \/>\n        viewToRotate.transform = viewToRotate.transform.rotated(by: rotation)<br \/>\n        sender.rotation = 0 \/\/ \u91cd\u7f6e\u65cb\u8f49\u4ee5\u4fbf\u65bc\u4e0b\u4e00\u6b21\u6aa2\u6e2c<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>\u5728\u9019\u6bb5\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 `sender.rotation` \u5c6c\u6027\u4f86\u7372\u53d6\u65cb\u8f49\u89d2\u5ea6\uff0c\u4e26\u5c07\u5176\u61c9\u7528\u65bc\u8996\u5716\u7684\u8b8a\u63db\uff08transform\uff09\u4e0a\u3002\u6bcf\u6b21\u65cb\u8f49\u5f8c\uff0c\u6211\u5011\u9084\u9700\u8981\u91cd\u7f6e `sender.rotation`\uff0c\u4ee5\u4fbf\u65bc\u4e0b\u6b21\u6aa2\u6e2c\u7684\u6e96\u78ba\u6027\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u5be6\u4f5c\u904e\u7a0b\u4e2d\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u7684\u554f\u984c\uff1a<\/p>\n<p>&#8211; **\u8996\u5716\u672a\u65cb\u8f49**\uff1a\u78ba\u4fdd\u624b\u52e2\u8b58\u5225\u5668\u5df2\u6b63\u78ba\u6dfb\u52a0\u5230\u8996\u5716\u3002\u6aa2\u67e5 `view.addGestureRecognizer(rotationGestureRecognizer)` \u662f\u5426\u6210\u529f\u57f7\u884c\u3002<br \/>\n&#8211; **\u65cb\u8f49\u4e0d\u6d41\u66a2**\uff1a\u78ba\u4fdd\u5728 `handleRotation` \u65b9\u6cd5\u4e2d\u6b63\u78ba\u91cd\u7f6e `sender.rotation`\uff0c\u4ee5\u907f\u514d\u7d2f\u7a4d\u65cb\u8f49\u503c\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u900f\u904e\u65cb\u8f49\u624b\u52e2\u8b58\u5225\u5668\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5275\u5efa\u591a\u7a2e\u6709\u8da3\u7684\u4ea4\u4e92\u6548\u679c\uff0c\u5982\u65cb\u8f49\u5716\u7247\u3001\u8996\u5716\u62163D\u7269\u4ef6\u7b49\u3002\u60a8\u4e5f\u53ef\u4ee5\u7d50\u5408\u5176\u4ed6\u624b\u52e2\u8b58\u5225\u5668\uff0c\u5982\u634f\u5408\u624b\u52e2\uff08UIPinchGestureRecognizer\uff09\uff0c\u4f86\u5be6\u73fe\u66f4\u8c50\u5bcc\u7684\u4e92\u52d5\u9ad4\u9a57\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 Swift \u4e2d\u7684 UIRotationGestureRecognizer \u5be6\u73fe\u65cb\u8f49\u624b\u52e2\u8b58\u5225\u5668\uff0c\u5305\u62ec\u6700\u65b0\u7684\u8a9e\u6cd5\u548c\u6700\u4f73\u5be6\u8e10\u3002\u900f\u904e\u9019\u4e9b\u77e5\u8b58\uff0c\u958b\u767c\u8005\u80fd\u5920\u66f4\u8f15\u9b06\u5730\u70ba\u61c9\u7528\u7a0b\u5e8f\u6dfb\u52a0\u4e92\u52d5\u6027\uff0c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2>\u5e38\u898b\u554f\u984c\u89e3\u7b54 (Q&#038;A)<\/h2>\n<p>**Q1: \u65cb\u8f49\u624b\u52e2\u8b58\u5225\u5668\u53ef\u4ee5\u8207\u5176\u4ed6\u624b\u52e2\u8b58\u5225\u5668\u4e00\u8d77\u4f7f\u7528\u55ce\uff1f**<br \/>\nA1: \u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u5c07\u65cb\u8f49\u624b\u52e2\u8b58\u5225\u5668\u8207\u634f\u5408\u624b\u52e2\u8b58\u5225\u5668\u6216\u5e73\u79fb\u624b\u52e2\u8b58\u5225\u5668\u4e00\u8d77\u4f7f\u7528\uff0c\u5275\u5efa\u66f4\u8907\u96dc\u7684\u4e92\u52d5\u6548\u679c\u3002<\/p>\n<p>**Q2: \u5982\u4f55\u5728\u65cb\u8f49\u624b\u52e2\u4e2d\u6dfb\u52a0\u52d5\u756b\u6548\u679c\uff1f**<br \/>\nA2: \u60a8\u53ef\u4ee5\u5728 `handleRotation` \u65b9\u6cd5\u4e2d\u4f7f\u7528 UIView \u7684\u52d5\u756b\u65b9\u6cd5\uff0c\u6839\u64da\u65cb\u8f49\u89d2\u5ea6\u6dfb\u52a0\u52d5\u756b\u6548\u679c\uff0c\u4f8b\u5982\u8996\u5716\u7684\u5e73\u6ed1\u65cb\u8f49\u3002<\/p>\n<p>**Q3: \u65cb\u8f49\u624b\u52e2\u8b58\u5225\u5668\u7684\u6027\u80fd\u5982\u4f55\uff1f**<br \/>\nA3: UIRotationGestureRecognizer \u5728\u6027\u80fd\u4e0a\u662f\u9ad8\u6548\u7684\uff0c\u9069\u5408\u7528\u65bc\u6d41\u66a2\u7684\u7528\u6236\u4ea4\u4e92\u3002\u5982\u679c\u5728\u8907\u96dc\u7684\u5834\u666f\u4e2d\u4f7f\u7528\uff0c\u8acb\u78ba\u4fdd\u9032\u884c\u6027\u80fd\u6e2c\u8a66\u4ee5\u7dad\u6301\u6d41\u66a2\u5ea6\u3002<\/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\u65cb\u8f6c\u624b\u52e2\u8b58\u5225\u5668\uff0c\u5305\u62ec\u5982\u4f55\u4f7f\u7528UIRotationGestureRecognizer\u985e\u4f86\u5be6\u73fe\u65cb\u8f6c\u624b\u52e2\u8b58\u5225\u5668\u3001\u5982\u4f55\u7372\u53d6\u65cb\u8f6c\u624b\u52e2\u7684\u65cb\u8f6c\u89d2\u5ea6\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-3967","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-11Z","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3967","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=3967"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3967\/revisions"}],"predecessor-version":[{"id":3968,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3967\/revisions\/3968"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}