{"id":3965,"date":"2025-06-04T11:47:36","date_gmt":"2025-06-05T03:50:35","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3965"},"modified":"2025-06-05T11:47:36","modified_gmt":"2025-06-05T03:50:35","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%e7%bc%a9%e6%94%be%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%e7%bc%a9%e6%94%be%e6%89%8b%e5%8a%bf%e8%af%86%e5%88%ab%e5%99%a8\/","title":{"rendered":"2025 \u6700\u65b0 Swift \u7a0b\u5f0f\u6559\u5b78\uff1a\u4f7f\u7528 UIPinchGestureRecognizer \u5be6\u73fe\u7e2e\u653e\u624b\u52e2\u8b58\u5225\u5668"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Swift, UIPinchGestureRecognizer, \u7f29\u653e\u624b\u52bf\u8bc6\u522b\u5668, \u624b\u52bf\u8bc6\u522b, Swift \u6559\u5b66, iOS \u5f00\u53d1\"><\/p>\n<h1>2025 \u6700\u65b0 Swift \u7a0b\u5f0f\u6559\u5b78\uff1a\u4f7f\u7528 UIPinchGestureRecognizer \u5be6\u73fe\u7e2e\u653e\u624b\u52e2\u8b58\u5225\u5668<\/h1>\n<p>Swift \u662f\u4e00\u7a2e\u529f\u80fd\u5f37\u5927\u7684\u7de8\u7a0b\u8a9e\u8a00\uff0c\u80fd\u8b93\u958b\u767c\u8005\u5feb\u901f\u958b\u767c\u51fa\u529f\u80fd\u8c50\u5bcc\u7684\u61c9\u7528\u7a0b\u5f0f\u3002\u5728 Swift \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528\u7e2e\u653e\u624b\u52e2\u8b58\u5225\u5668\u4f86\u5be6\u73fe\u7528\u6236\u7684\u7e2e\u653e\u64cd\u4f5c\u3002\u672c\u6587\u5c07\u5168\u9762\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Swift \u4e2d\u7684 UIPinchGestureRecognizer \u985e\u4f86\u5be6\u73fe\u7e2e\u653e\u624b\u52e2\u8b58\u5225\uff0c\u5305\u62ec\u624b\u52e2\u7684\u8a2d\u7f6e\u3001\u7e2e\u653e\u56e0\u5b50\u7684\u7372\u53d6\u53ca\u5be6\u4f5c\u7bc4\u4f8b\u3002<\/p>\n<h2>\u4f7f\u7528 UIPinchGestureRecognizer \u985e\u5be6\u73fe\u7e2e\u653e\u624b\u52e2\u8b58\u5225\u5668<\/h2>\n<p>\u8981\u5be6\u73fe\u7e2e\u653e\u624b\u52e2\u8b58\u5225\u5668\uff0c\u9996\u5148\u9700\u8981\u5275\u5efa\u4e00\u500b UIPinchGestureRecognizer \u5c0d\u8c61\uff0c\u4e26\u5c07\u5176\u6dfb\u52a0\u5230\u8981\u8b58\u5225\u7e2e\u653e\u624b\u52e2\u7684\u8996\u5716\u4e0a\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u5be6\u73fe\u6b65\u9a5f\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nlet pinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(handlePinchGesture))<br \/>\nview.addGestureRecognizer(pinchGestureRecognizer)<br \/>\n&#8220;`<\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b UIPinchGestureRecognizer \u5c0d\u8c61\u4e26\u5c07\u5176\u6dfb\u52a0\u5230\u8996\u5716\u4e0a\u3002\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5be6\u73fe `handlePinchGesture` \u65b9\u6cd5\uff0c\u4ee5\u4fbf\u5728\u7528\u6236\u767c\u751f\u7e2e\u653e\u624b\u52e2\u6642\u505a\u51fa\u76f8\u61c9\u7684\u8655\u7406\u3002<\/p>\n<p>&#8220;`swift<br \/>\n@objc func handlePinchGesture(sender: UIPinchGestureRecognizer) {<br \/>\n    \/\/ \u9019\u88e1\u53ef\u4ee5\u6dfb\u52a0\u5c0d\u7e2e\u653e\u624b\u52e2\u7684\u97ff\u61c9\u4ee3\u78bc<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2>\u7372\u53d6\u7e2e\u653e\u624b\u52e2\u7684\u7e2e\u653e\u56e0\u5b50<\/h2>\n<p>\u5728 `handlePinchGesture` \u65b9\u6cd5\u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 `sender.scale` \u5c6c\u6027\u4f86\u7372\u53d6\u7e2e\u653e\u624b\u52e2\u7684\u7e2e\u653e\u56e0\u5b50\uff0c\u9019\u662f\u4e00\u500b\u6d6e\u9ede\u6578\uff0c\u8868\u793a\u7528\u6236\u624b\u52e2\u7684\u7e2e\u653e\u7a0b\u5ea6\u3002\u7576\u7528\u6236\u653e\u5927\u624b\u52e2\u6642\uff0c\u7e2e\u653e\u56e0\u5b50\u6703\u5927\u65bc 1\uff1b\u53cd\u4e4b\uff0c\u7576\u7528\u6236\u7e2e\u5c0f\u624b\u52e2\u6642\uff0c\u7e2e\u653e\u56e0\u5b50\u6703\u5c0f\u65bc 1\u3002<\/p>\n<p>&#8220;`swift<br \/>\n@objc func handlePinchGesture(sender: UIPinchGestureRecognizer) {<br \/>\n    let scale = sender.scale<br \/>\n    \/\/ \u6839\u64da\u7e2e\u653e\u56e0\u5b50\u8abf\u6574\u8996\u5716\u6216\u57f7\u884c\u5176\u4ed6\u64cd\u4f5c<br \/>\n    print(&#8220;\u7576\u524d\u7e2e\u653e\u56e0\u5b50\uff1a\\(scale)&#8221;)<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2>\u932f\u8aa4\u6392\u9664\u8207\u6700\u4f73\u5be6\u8e10<\/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>1. **\u624b\u52e2\u6c92\u6709\u88ab\u8b58\u5225\uff1a** \u78ba\u4fdd\u60a8\u7684\u8996\u5716\u53ef\u4ee5\u63a5\u6536\u89f8\u6478\u4e8b\u4ef6\uff0c\u4e14\u6c92\u6709\u5176\u4ed6\u624b\u52e2\u8b58\u5225\u5668\u963b\u6b62\u4e86\u9019\u500b\u624b\u52e2\u7684\u8b58\u5225\u3002<\/p>\n<p>2. **\u7e2e\u653e\u6548\u679c\u4e0d\u5982\u9810\u671f\uff1a** \u6aa2\u67e5\u60a8\u7684\u7e2e\u653e\u908f\u8f2f\uff0c\u78ba\u4fdd\u5728\u7e2e\u653e\u624b\u52e2\u767c\u751f\u6642\uff0c\u6839\u64da `scale` \u5c6c\u6027\u6b63\u78ba\u66f4\u65b0\u8996\u5716\u7684\u5927\u5c0f\u6216\u8b8a\u63db\u3002<\/p>\n<p>\u70ba\u4e86\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6236\u9ad4\u9a57\uff0c\u60a8\u53ef\u4ee5\u8003\u616e\u6839\u64da\u7e2e\u653e\u56e0\u5b50\u9032\u884c\u52d5\u756b\u6548\u679c\uff0c\u6216\u5728\u8996\u5716\u7e2e\u653e\u6642\u9650\u5236\u5176\u7e2e\u653e\u7bc4\u570d\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u57fa\u672c\u7684\u7e2e\u653e\u624b\u52e2\u8b58\u5225\u5916\uff0c\u60a8\u9084\u53ef\u4ee5\u5c07\u5176\u8207\u5176\u4ed6\u624b\u52e2\u8b58\u5225\u5668\u7d50\u5408\u4f7f\u7528\uff0c\u5982\u65cb\u8f49\u624b\u52e2\u6216\u5e73\u79fb\u624b\u52e2\uff0c\u4f86\u589e\u5f37\u7528\u6236\u4ea4\u4e92\u9ad4\u9a57\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u540c\u6642\u5be6\u73fe\u7e2e\u653e\u548c\u65cb\u8f49\u529f\u80fd\uff0c\u8b93\u7528\u6236\u80fd\u5920\u66f4\u9748\u6d3b\u5730\u64cd\u4f5c\u5716\u50cf\u6216\u5730\u5716\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 Swift \u4e2d\u7684 UIPinchGestureRecognizer \u985e\u4f86\u5be6\u73fe\u7e2e\u653e\u624b\u52e2\u8b58\u5225\u5668\uff0c\u5305\u62ec\u5982\u4f55\u8a2d\u7f6e\u624b\u52e2\u3001\u7372\u53d6\u7e2e\u653e\u56e0\u5b50\u53ca\u4e00\u4e9b\u5be6\u4f5c\u5efa\u8b70\u3002\u900f\u904e\u6709\u6548\u7684\u624b\u52e2\u8b58\u5225\uff0c\u958b\u767c\u8005\u80fd\u70ba\u7528\u6236\u63d0\u4f9b\u66f4\u4f73\u7684\u4e92\u52d5\u9ad4\u9a57\u3002<\/p>\n<h2>\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff08Q&#038;A\uff09<\/h2>\n<p>**Q1: \u5982\u4f55\u5728\u591a\u500b\u624b\u52e2\u8b58\u5225\u5668\u4e2d\u7ba1\u7406\u512a\u5148\u9806\u5e8f\uff1f**<br \/>\nA1: \u4f60\u53ef\u4ee5\u4f7f\u7528 `require(toFail:)` \u65b9\u6cd5\u4f86\u8a2d\u7f6e\u624b\u52e2\u8b58\u5225\u5668\u7684\u512a\u5148\u9806\u5e8f\uff0c\u4ee5\u78ba\u4fdd\u67d0\u4e9b\u624b\u52e2\u5728\u5176\u4ed6\u624b\u52e2\u4e4b\u524d\u88ab\u8b58\u5225\u3002<\/p>\n<p>**Q2: \u5982\u4f55\u9650\u5236\u7e2e\u653e\u7684\u6700\u5c0f\u548c\u6700\u5927\u6bd4\u4f8b\uff1f**<br \/>\nA2: \u5728 `handlePinchGesture` \u65b9\u6cd5\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6aa2\u67e5\u7e2e\u653e\u56e0\u5b50\u7684\u503c\uff0c\u4e26\u6839\u64da\u9700\u8981\u8abf\u6574\u8996\u5716\u7684\u5927\u5c0f\uff0c\u907f\u514d\u904e\u5ea6\u7e2e\u653e\u3002<\/p>\n<p>**Q3: UIPinchGestureRecognizer \u53ef\u4ee5\u8207\u5176\u4ed6\u624b\u52e2\u8b58\u5225\u5668\u4e00\u8d77\u4f7f\u7528\u55ce\uff1f**<br \/>\nA3: \u53ef\u4ee5\uff0cUIPinchGestureRecognizer \u53ef\u4ee5\u8207\u5176\u4ed6\u624b\u52e2\u8b58\u5225\u5668\uff08\u5982 UIPanGestureRecognizer \u6216 UIRotationGestureRecognizer\uff09\u4e00\u8d77\u4f7f\u7528\uff0c\u53ea\u9700\u6ce8\u610f\u7ba1\u7406\u5b83\u5011\u4e4b\u9593\u7684\u885d\u7a81\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\u7f29\u653e\u624b\u52bf\u8bc6\u522b\u5668\uff0c\u5305\u62ec\u5982\u4f55\u4f7f\u7528UIPinchGestureRecognizer\u7c7b\u6765\u5b9e\u73b0\u7f29\u653e\u624b\u52bf\u8bc6\u522b\u5668\u3001\u5982\u4f55\u83b7\u53d6\u7f29\u653e\u624b\u52bf\u7684\u7f29\u653e\u56e0\u5b50\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-3965","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-11X","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3965","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=3965"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3965\/revisions"}],"predecessor-version":[{"id":3966,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3965\/revisions\/3966"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}