{"id":7048,"date":"2025-06-01T13:33:51","date_gmt":"2025-06-05T05:45:51","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7048"},"modified":"2025-06-05T13:33:51","modified_gmt":"2025-06-05T05:45:51","slug":"https-badgameshow-com-steven-200","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-200\/","title":{"rendered":"2025 \u6700\u65b0 Swift \u5be6\u73fe 3D Touch \u6548\u679c\u6559\u5b78"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, 3D Touch, iOS, Swift \u6559\u5b78, 2025 \u6700\u65b0\u8a9e\u6cd5\"><\/p>\n<h1>2025 \u6700\u65b0 Swift \u5be6\u73fe 3D Touch \u6548\u679c\u6559\u5b78<\/h1>\n<p>3D Touch \u662f Apple \u5728 2015 \u5e74\u63a8\u51fa\u7684\u4e00\u9805\u529f\u80fd\uff0c\u5141\u8a31\u4f7f\u7528\u8005\u900f\u904e\u6df1\u6309\u87a2\u5e55\u9032\u884c\u66f4\u591a\u64cd\u4f5c\u3002\u96a8\u8457\u6280\u8853\u7684\u767c\u5c55\uff0cApple \u5728\u65b0\u8a2d\u5099\u4e0a\u9010\u6f38\u5c07 3D Touch \u66ff\u63db\u70ba\u89f8\u89ba\u53cd\u994b\uff08Haptic Touch\uff09\uff0c\u56e0\u6b64\u5728 Swift \u4e2d\u5be6\u73fe\u9019\u4e00\u529f\u80fd\u7684\u65b9\u5f0f\u4e5f\u5728\u4e0d\u65b7\u6f14\u9032\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Swift \u4f86\u5be6\u73fe 3D Touch \u6548\u679c\uff0c\u4e26\u63d0\u4f9b 2025 \u5e74\u6700\u65b0\u7684\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 Swift \u5be6\u73fe 3D Touch \u6548\u679c\uff1f<\/h2>\n<p>\u8981\u5728\u4f60\u7684 App \u4e2d\u5be6\u73fe 3D Touch \u6548\u679c\uff0c\u9996\u5148\u9700\u8981\u914d\u7f6e <strong>UIApplicationShortcutItem<\/strong>\uff0c\u9019\u6a23\u53ef\u4ee5\u8b93\u4f7f\u7528\u8005\u900f\u904e\u5feb\u6377\u9375\u5feb\u901f\u57f7\u884c\u67d0\u4e9b\u52d5\u4f5c\u3002\u63a5\u8457\uff0c\u5be6\u73fe <strong>UIApplicationShortcutItemDelegate<\/strong> \u4f86\u8655\u7406\u9019\u4e9b\u5feb\u6377\u9375\u7684\u884c\u70ba\uff0c\u6700\u5f8c\u4f7f\u7528 <strong>UIPreviewAction<\/strong> \u4f86\u63d0\u4f9b\u9810\u89bd\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u5177\u9ad4\u6b65\u9a5f\uff1a<\/p>\n<h3>\u6b65\u9a5f 1\uff1a\u914d\u7f6e UIApplicationShortcutItem<\/h3>\n<p>\u5728\u4f60\u7684 App \u7684 Info.plist \u4e2d\uff0c\u6dfb\u52a0 <code>UIApplicationShortcutItems<\/code> \u9375\uff0c\u4e26\u914d\u7f6e\u5feb\u6377\u9375\u7684\u5c6c\u6027\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code>\n<key>UIApplicationShortcutItems<\/key>\n<array>\n    <dict>\n        <key>UIApplicationShortcutItemType<\/key>\n        <string>com.example.app.openFavorites<\/string>\n        <key>UIApplicationShortcutItemTitle<\/key>\n        <string>\u958b\u555f\u6700\u611b<\/string>\n    <\/dict>\n<\/array>\n<\/code><\/pre>\n<h3>\u6b65\u9a5f 2\uff1a\u5be6\u73fe UIApplicationShortcutItemDelegate<\/h3>\n<p>\u5728\u4f60\u7684 App \u59d4\u6d3e\u4e2d\uff0c\u5be6\u73fe\u4ee5\u4e0b\u65b9\u6cd5\u4f86\u8655\u7406\u5feb\u6377\u9375\u7684\u884c\u70ba\uff1a<\/p>\n<pre><code>\nfunc application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {\n    if shortcutItem.type == \"com.example.app.openFavorites\" {\n        \/\/ \u8655\u7406\u5feb\u6377\u9375\u884c\u70ba\uff0c\u4f8b\u5982\u5c0e\u822a\u5230\u6700\u611b\u9801\u9762\n        completionHandler(true)\n    } else {\n        completionHandler(false)\n    }\n}\n<\/code><\/pre>\n<h3>\u6b65\u9a5f 3\uff1a\u4f7f\u7528 UIPreviewAction \u5be6\u73fe\u9810\u89bd\u529f\u80fd<\/h3>\n<p>\u5728\u4f60\u7684\u8996\u5716\u63a7\u5236\u5668\u4e2d\uff0c\u5be6\u73fe\u4e0b\u5217\u65b9\u6cd5\u4ee5\u652f\u6301\u6df1\u6309\u9810\u89bd\uff1a<\/p>\n<pre><code>\noverride func previewActionItems() -> [UIPreviewActionItem] {\n    let favoriteAction = UIPreviewAction(title: \"\u52a0\u5165\u6700\u611b\", style: .default) { (action, viewController) in\n        \/\/ \u52a0\u5165\u6700\u611b\u7684\u908f\u8f2f\n    }\n    return [favoriteAction]\n}\n<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5982\u679c\u4f60\u5728\u5be6\u73fe\u904e\u7a0b\u4e2d\u9047\u5230\u554f\u984c\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u932f\u8aa4\u53ca\u89e3\u6c7a\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li><strong>\u5feb\u6377\u9375\u4e0d\u986f\u793a\uff1a<\/strong>\u78ba\u4fdd\u5728 Info.plist \u4e2d\u6b63\u78ba\u914d\u7f6e\u4e86 <code>UIApplicationShortcutItems<\/code>\u3002<\/li>\n<li><strong>\u9810\u89bd\u529f\u80fd\u7121\u6cd5\u4f7f\u7528\uff1a<\/strong>\u6aa2\u67e5\u662f\u5426\u5728\u6b63\u78ba\u7684\u8996\u5716\u63a7\u5236\u5668\u4e2d\u5be6\u73fe\u4e86 <code>previewActionItems<\/code> \u65b9\u6cd5\u3002<\/li>\n<li><strong>\u5feb\u6377\u9375\u884c\u70ba\u672a\u89f8\u767c\uff1a<\/strong>\u78ba\u8a8d\u4f60\u5728 App \u59d4\u6d3e\u4e2d\u6b63\u78ba\u5be6\u73fe\u4e86 <code>performActionFor<\/code> \u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u57fa\u672c\u7684 3D Touch \u6548\u679c\uff0c\u4f60\u9084\u53ef\u4ee5\u8003\u616e\u4ee5\u4e0b\u5ef6\u4f38\u61c9\u7528\uff1a<\/p>\n<ul>\n<li>\u6574\u5408 Haptic Touch \u4ee5\u63d0\u5347\u4f7f\u7528\u8005\u4e92\u52d5\u9ad4\u9a57\u3002<\/li>\n<li>\u4f7f\u7528 SwiftUI \u5be6\u73fe\u66f4\u73fe\u4ee3\u5316\u7684 UI \u53cd\u61c9\uff0c\u7d50\u5408\u89f8\u63a7\u624b\u52e2\u4f86\u66ff\u4ee3 3D Touch\u3002<\/li>\n<\/ul>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u900f\u904e\u4f7f\u7528 Swift \u5be6\u73fe 3D Touch \u6548\u679c\uff0c\u4f60\u7684 App \u5c07\u8b8a\u5f97\u66f4\u52a0\u8c50\u5bcc\u548c\u6613\u65bc\u64cd\u4f5c\u3002\u96a8\u8457 iOS \u7684\u66f4\u65b0\uff0c\u4fdd\u6301\u6280\u8853\u7684\u8207\u6642\u4ff1\u9032\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5e0c\u671b\u9019\u7bc7\u6587\u7ae0\u80fd\u5e6b\u52a9\u4f60\u5728 2025 \u5e74\u5be6\u73fe\u6700\u65b0\u7684 3D Touch \u6548\u679c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5be6\u73fe3D-Touch\u6548\u679c-\ud83d\udcaa_1675401355.726547.webp\" alt=\"Swift \u5be6\u73fe3D Touch\u6548\u679c \ud83d\udcaa\" title=\"Swift 3D Touch, UITouch, UIPreviewActionItem, 3D Touch \u6548\u679c, 3D Touch \u529f\u80fd\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: 3D Touch \u5728\u6240\u6709 iPhone \u578b\u865f\u4e0a\u90fd\u80fd\u4f7f\u7528\u55ce\uff1f<\/h3>\n<p>A1: \u4e0d\u662f\uff0c3D Touch \u50c5\u652f\u6301\u67d0\u4e9b\u578b\u865f\u7684 iPhone\uff0c\u5f8c\u7e8c\u578b\u865f\u591a\u6578\u4f7f\u7528 Haptic Touch \u66ff\u4ee3\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u5728 SwiftUI \u4e2d\u5be6\u73fe\u985e\u4f3c 3D Touch \u7684\u6548\u679c\uff1f<\/h3>\n<p>A2: \u5728 SwiftUI \u4e2d\u53ef\u4ee5\u4f7f\u7528\u89f8\u63a7\u624b\u52e2\uff08\u5982 <code>onTapGesture<\/code> \u548c <code>onLongPressGesture<\/code>\uff09\u4f86\u6a21\u64ec\u76f8\u4f3c\u7684\u884c\u70ba\u3002<\/p>\n<h3>Q3: 3D Touch \u6548\u679c\u662f\u5426\u6703\u5f71\u97ff App \u7684\u6027\u80fd\uff1f<\/h3>\n<p>A3: \u9069\u7576\u4f7f\u7528 3D Touch \u4e0d\u6703\u986f\u8457\u5f71\u97ff\u6027\u80fd\uff0c\u4f46\u904e\u5ea6\u4f7f\u7528\u53ef\u80fd\u6703\u5c0e\u81f4\u4e0d\u5fc5\u8981\u7684\u8907\u96dc\u6027\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u8a9e\u8a00\u4f86\u5be6\u73fe3DTouch\u6548\u679c\uff0c\u4e26\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528UITouch\u4f86\u6aa2\u6e2c\u7528\u6236\u7684\u89f8\u6478\u52d5\u4f5c\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528UIPreviewActionItem\u4f86\u5be6\u73fe3DTouch\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":7047,"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-7048","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-\u5be6\u73fe3D-Touch\u6548\u679c-\ud83d\udcaa_1675401355.726547.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1PG","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7048","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=7048"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7048\/revisions"}],"predecessor-version":[{"id":13258,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7048\/revisions\/13258"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7047"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}