{"id":657,"date":"2020-08-15T11:59:11","date_gmt":"2020-08-15T03:59:11","guid":{"rendered":"http:\/\/123.57.164.21\/?p=657"},"modified":"2020-08-15T21:34:40","modified_gmt":"2020-08-15T13:34:40","slug":"swiftui%e5%8a%a8%e7%94%bb1-animatable","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=657","title":{"rendered":"SwiftUI\u52a8\u753b(1) Animatable"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">1.\u9996\u5148\u4e86\u89e3\u4e00\u4e2a\u6982\u5ff5\uff1a<strong>\u663e\u5f0f\u548c\u9690\u5f0f\u52a8\u753b<\/strong><\/h4>\n\n\n\n<p>SwiftUI\u4e2d\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u52a8\u753b\uff0c\u663e\u5f0f\u548c\u9690\u5f0f\u3002<\/p>\n\n\n\n<p>\u9690\u5f0f\u52a8\u753b\u6307\u7684\u5c31\u662f\u7528.animation() modifier\u7684view\uff0c\u5f53\u8be5view\u7684\u53ef\u52a8\u753b\u7684\u53c2\u6570\u53d8\u5316\u7684\u65f6\u5019\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u8fdb\u884c\u52a8\u753b\uff0c\u8fd9\u4e9b\u6240\u8c13\u7684\u53ef\u52a8\u753b\u7684\u53c2\u6570\u5305\u62ecsize,  offset\uff0ccolor\uff0cscale\u7b49\u7b49\u3002<\/p>\n\n\n\n<p>\u663e\u5f0f\u52a8\u753b\u6307\u7684\u662f<code>withAnimation { ... }<\/code> \u95ed\u5305\u4e2d\u6307\u5b9a\u7684\u53c2\u6570\uff0c\u6240\u6709\u4f9d\u8d56\u8fd9\u4e9b\u53c2\u6570\u7684view\uff0c\u90fd\u4f1a\u6267\u884c\u52a8\u753b\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u5148\u770b\u4e2a\u4f8b\u5b50\uff0c\u4e0b\u8fb9\u7684\u52a8\u753b\u4f7f\u7528\u4e86\u9690\u5f0f\u52a8\u753b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"548\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-a77db86b7bfd8fbc.gif\" alt=\"\" class=\"wp-image-659\"\/><\/figure><\/div>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct Example1: View {\n    @State private var half = false\n    @State private var dim = false\n    \n    var body: some View {\n        Image(\"tower\")\n            .scaleEffect(half ? 0.5 : 1.0)\n            .opacity(dim ? 0.2 : 1.0)\n            .animation(.easeInOut(duration: 1.0))\n            .onTapGesture {\n                self.dim.toggle()\n                self.half.toggle()\n            }\n    }\n}<\/pre>\n\n\n\n<p>\u4ece\u4e0a\u8fb9\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\u52a8\u753b\u4f9d\u8d56<code>half<\/code>,  <code>dim<\/code>\u8fd92\u4e2a\u53c2\u6570\uff0c\u6211\u4eec\u5e76\u6ca1\u6709\u76f4\u63a5\u544a\u8bc9view\u8fd92\u4e2a\u53c2\u6570\u8981\u52a8\u753b\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u628a\u65e7\u503c\u5230\u65b0\u503c\u7684\u53d8\u5316\u505a\u52a8\u753b\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u7684\u4f8b\u5b50\u5c31\u662f\u663e\u793a\u52a8\u753b\uff0c\u900f\u660e\u5ea6\u548c\u7f29\u653e\u90fd\u6539\u53d8\u7684\u65f6\u5019\uff0c\u4f46\u53ea\u6709\u900f\u660e\u5ea6\u4f1a\u505a\u52a8\u753b\uff0c\u56e0\u4e3a\u53ea\u6709\u8fd9\u4e00\u4e2a\u53c2\u6570\u5728<code>withAnimation<\/code>\u95ed\u5305\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct Example2: View {\n    @State private var half = false\n    @State private var dim = false\n    \n    var body: some View {\n        Image(\"tower\")\n            .scaleEffect(half ? 0.5 : 1.0)\n            .opacity(dim ? 0.5 : 1.0)\n            .onTapGesture {\n                self.half.toggle()\n                \n                withAnimation(.easeInOut(duration: 1.0)) {\n                    self.dim.toggle()\n                }\n        }\n    }\n}<\/pre>\n\n\n\n<p>\u6211\u4eec\u53bb\u6389\u4e86<code>.animation(.easeInOut(duration: 1.0))<\/code>, \u65b0\u589e\u4e86<code>withAnimation<\/code>\u95ed\u5305\uff0c\u6211\u4eec\u628a<code>self.dim.toggle()<\/code>\u653e\u5230\u95ed\u5305\u4e2d\uff0c\u8fd9\u5c31\u662f\u663e\u5f0f\u7684\u544a\u8bc9\u7cfb\u7edf\uff0cview\u7684\u900f\u660e\u5ea6\u8981\u6267\u884c\u52a8\u753b\uff0c\u6240\u6709\u4f9d\u8d56<code>dim<\/code>\u53c2\u6570\u7684view\uff0c\u5728dim\u6539\u53d8\u7684\u65f6\u5019\uff0c\u90fd\u4f1a\u6267\u884c\u52a8\u753b\uff0c\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"548\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-aba5200a962432f1.gif\" alt=\"\" class=\"wp-image-662\"\/><\/figure><\/div>\n\n\n\n<p>\u4ed4\u7ec6\u770b\u4e0a\u56fe\u7684\u52a8\u753b\u8fc7\u7a0b\uff0c\u5c31\u4f1a\u53d1\u73b0\uff0c\u53ea\u6709\u900f\u660e\u5ea6\u6307\u5b9a\u4e86\u52a8\u753b\uff0c\u7f29\u653e\u5e76\u6ca1\u6709\u6267\u884c\u52a8\u753b\uff0c\u8fd9\u5c31\u8bf4\u660e\uff0c\u6211\u4eec\u663e\u5f0f\u7684\u544a\u8bc9\u7cfb\u7edf<code>dim<\/code>\u9700\u8981\u52a8\u753b\uff0c\u5b83\u5c31\u53ea\u4e3a<code>dim<\/code>\u6267\u884c\u52a8\u753b\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u7528\u9690\u5f0f\u52a8\u753b\u5982\u4f55\u5b9e\u73b0\u4e0a\u8fb9\u8fd9\u79cd\u52a8\u753b\u5462\uff1f\u4e5f\u975e\u5e38\u7b80\u5355,  \u5148\u770b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct Example2: View {\n    @State private var half = false\n    @State private var dim = false\n    \n    var body: some View {\n        Image(\"tower\")\n            .opacity(dim ? 0.2 : 1.0)\n            .animation(.easeInOut(duration: 1.0))\n            .scaleEffect(half ? 0.5 : 1.0)\n            .onTapGesture {\n                self.dim.toggle()\n                self.half.toggle()\n        }\n    }\n}<\/pre>\n\n\n\n<p>\u5f53<code>animation<\/code>  modifier\u4f5c\u7528\u4e8eview\u65f6\uff0c\u4ed6\u7684\u987a\u5e8f\u65f6\u5f88\u91cd\u8981\u7684\uff0c\u5728\u4e0a\u8fb9\u7684\u4ee3\u7801\u4e2d\uff0c\u5b83\u53ea\u5bf9\u5b83\u524d\u8fb9\u7684\u5185\u5bb9\u751f\u6548\uff0c\u5f53\u7136\u8fd9\u4e2a\u987a\u5e8f\u6211\u4eec\u5176\u5b9e\u65f6\u53ef\u4ee5\u4efb\u610f\u8c03\u6574\u7684\uff0c\u6211\u4eec\u8981\u60f3\u4f7f\u7528\u9690\u5f0f\u52a8\u753b\u7981\u7528\u67d0\u4e9b\u52a8\u753b\u65f6\uff0c\u53ea\u9700\u8981<code>.animation(nil)<\/code>\u5c31\u884c\u4e86\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct Example2: View {\n    @State private var half = false\n    @State private var dim = false\n    \n    var body: some View {\n        Image(\"tower\")\n            .opacity(dim ? 0.2 : 1.0)\n            .animation(nil)\n            .scaleEffect(half ? 0.5 : 1.0)\n                .animation(.easeInOut(duration: 1.0))\n            .onTapGesture {\n                self.dim.toggle()\n                self.half.toggle()\n        }\n    }\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">2.\u52a8\u753b\u662f\u600e\u4e48\u5b9e\u73b0\u7684<\/h4>\n\n\n\n<p>\u5728\u6240\u6709SwiftUI\u52a8\u753b\u7684\u80cc\u540e\uff0c\u90fd\u6709\u4e00\u4e2a\u53eb\u505a<code>Animatable<\/code>\u7684\u534f\u8bae\uff0c\u5b83\u5305\u62ec\u4e00\u4e2a\u9075\u5faa<code>VectorArithmetic(\u77e2\u91cf\u8fd0\u7b97)<\/code>\u534f\u8bae\u7684\u8ba1\u7b97\u578b\u5c5e\u6027\u3002<code>VectorArithmetic<\/code>\u7684\u76ee\u7684\u662f\u8ba9\u7cfb\u7edf\u53ef\u4ee5\u5728\u9700\u8981\u53d8\u5316\u7684\u52a8\u753b\u6570\u636e\u4e2d\u95f4\u63d2\u5165\u5f88\u591a\u503c\uff0c\u8fd9\u4e9b\u503c\u7684\u8ba1\u7b97\u4f9d\u8d56\u52a8\u753b\u7684\u65f6\u95f4\u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u672c\u8d28\u4e0a\uff0c\u5f53\u4e00\u4e2a\u89c6\u56fe\u505a\u52a8\u753b\u7684\u65f6\u5019\uff0cSwiftUI\u5df2\u7ecf\u5f88\u591a\u6b21\u7684\u751f\u6210\u89c6\u56fe\u4e86\u3002\u6bcf\u6b21\u90fd\u4f1a\u4fee\u6539\u52a8\u753b\u53c2\u6570\uff0c\u8fd9\u6837\u52a8\u753b\u53c2\u6570\u5c31\u53ef\u4ee5\u4ece\u539f\u59cb\u503c\u9010\u6e10\u53d8\u6210\u6700\u7ec8\u503c\u3002<\/p>\n\n\n\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u6211\u4eec\u7ebf\u6027\u7684\u628a\u900f\u660e\u5ea6\u4ece0.3\u6539\u62100.8\uff0c\u7531\u4e8e0.3\u662f<code>Double<\/code>\u7c7b\u578b\uff0c\u5b9e\u73b0\u4e86<code>VectorArithmetic<\/code>\u534f\u8bae\uff0c\u56e0\u6b64\u7cfb\u7edf\u53ef\u4ee5\u57280.3\u52300.8\u4e4b\u95f4\u63d2\u5165\u5f88\u5bf9\u4e2d\u95f4\u7684\u503c\uff0c\u8fd9\u4e9b\u503c\u7684\u8ba1\u7b97\u4f9d\u8d56\u65f6\u95f4\u51fd\u6570\u548c\u52a8\u753b\u65f6\u957f\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u5b83\u662f\u7ebf\u6027\u7684\uff0c\u5728\u7cfb\u7edf\u7684\u67d0\u5904\uff0c\u53ef\u80fd\u5c31\u4f1a\u6709\u4e0b\u9762\u7684\u8ba1\u7b97\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">let from:Double = 0.3\nlet to:Double = 0.8\n\nfor i in 0..&lt;6 {\n    let pct = Double(i) \/ 5\n    \n    var difference = to - from\n    difference.scale(by: pct)\n    \n    let currentOpacity = from + difference\n    \n    print(\"currentOpacity = \\(currentOpacity)\")\n}\n\ncurrentOpacity = 0.3\ncurrentOpacity = 0.4\ncurrentOpacity = 0.5\ncurrentOpacity = 0.6\ncurrentOpacity = 0.7\ncurrentOpacity = 0.8<\/pre>\n\n\n\n<p><strong>\u672c\u8d28\u4e0a\uff0c\u7cfb\u7edf\u4f1a\u4e3a\u8fd9\u4e9b\u63d2\u5165\u7684\u503c\uff0c\u90fd\u751f\u6210\u4e00\u4e2aView\uff0c\u5728duration\u7684\u65f6\u95f4\u5185\u628a\u8fd9\u4e9bViews\uff0c\u64ad\u653e\u51fa\u6765\uff0c\u8fd9\u5c31\u662f\u6211\u4eec\u770b\u5230\u7684\u52a8\u753b\u6548\u679c\u3002<\/strong><\/p>\n\n\n\n<p>\u5173\u4e8e\u65f6\u95f4\u51fd\u6570\uff0c\u6211\u4eec\u7528\u4e0b\u8fb9\u7684\u8fd9\u5f20\u56fe\u6765\u4e3e\u4f8b\uff0c \u8fd9\u662f\u4e00\u4e2a\u56fe\u7247\u7684scale\uff0c\u4e5f\u5c31\u662f\u7f29\u653e\u6548\u679c\uff0c\u53ef\u4ee5\u770b\u5230\uff0c\u4e0d\u540c\u7684\u51fd\u6570\u4e0b\uff0c\u7cfb\u7edf\u63d2\u5165\u7684\u503c\u4e0d\u540c\uff0c\u6839\u636e\u63d2\u5165\u503c\u8ba1\u7b97\u7f29\u653e\u540e\u7684\u56fe\u7247\u4e5f\u662f\u4e0d\u540c\u7684\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"277\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-8993eaface1475a2-1024x277.png\" alt=\"\" class=\"wp-image-671\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-8993eaface1475a2-1024x277.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-8993eaface1475a2-300x81.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-8993eaface1475a2-768x208.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-8993eaface1475a2-1536x416.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-8993eaface1475a2-830x225.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-8993eaface1475a2-230x62.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-8993eaface1475a2-350x95.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-8993eaface1475a2-480x130.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-8993eaface1475a2.png 1824w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">3.\u4e3a\u4ec0\u4e48\u5173\u6ce8\u52a8\u753b?<\/h4>\n\n\n\n<p>\u4f60\u53ef\u80fd\u60f3\u77e5\u9053\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u5173\u6ce8\u8fd9\u4e9b\u7ec6\u8282\u3002SwiftUI\u8bbe\u7f6e\u4e0d\u900f\u660e\u7684\u52a8\u753b\uff0c\u5c31\u662f\u6539\u53d8\u4e0d\u900f\u660e\u5ea6\uff0c\u5c31\u53ea\u662f\u7b80\u5355\u7684\u5728\u521d\u59cb\u503c\u548c\u6700\u7ec8\u503c\u4e4b\u95f4\u63d2\u503c\uff0c\u4f46\u662f\u6211\u4eec\u63a5\u4e0b\u6765\u770b\u5230\u7684\u5e76\u975e\u8fd9\u4e48\u7b80\u5355\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u4e3a\u4ec0\u4e48\u6211\u4eec\u9700\u8981\u5982\u6b64\u5173\u6ce8<code>Animatable<\/code>\u8fd9\u4e2a\u534f\u8bae\u5462\uff1f \u50cfopacity\uff0cscale\uff0c\u8fd9\u4e9b\u7cfb\u7edf\u81ea\u52a8\u4f1a\u6267\u884c\u52a8\u753b\uff0c\u5b8c\u5168\u4e0d\u9700\u8981\u6211\u4eec\u5173\u5fc3\u3002<\/p>\n\n\n\n<p>\u662f\u7684\uff0c\u50cf\u8fd9\u4e9b\u57fa\u672c\u7684\u6548\u679c\uff0c\u7cfb\u7edf\u662f\u77e5\u9053\u8be5\u5982\u4f55\u505a\u52a8\u753b\u7684\uff0c\u4f46\u5728\u5e73\u65f6\u7684\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u8981\u505a\u7684\u52a8\u753b\u5f80\u5f80\u4e0d\u662f\u8fd9\u4e48\u7b80\u5355\uff0c\u6bd4\u5982\u8bf4\uff0cpath\u7684\u53d8\u6362\uff0c\u6e10\u53d8\u8272\u7684\u5207\u6362\u7b49\u7b49\uff0c\u8fd9\u4e9b\u4f8b\u5b50\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\u90fd\u4ecb\u7ecd\u5230\uff0c\u5176\u6700\u6838\u5fc3\u7684\u601d\u60f3\u5c31\u662f<code>animatableData<\/code>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">4.\u52a8\u753b\u7684\u5f62\u72b6\u8def\u5f84<\/h4>\n\n\n\n<p>\u8fd9\u4e00\u5c0f\u8282\uff0c\u6211\u4eec\u8981\u505a\u7684\u4e8b\u60c5\u5c31\u662f\u5229\u7528<code>Animatable<\/code>\u6765\u5b9e\u73b0\u6b63\u591a\u8fb9\u5f62\u7684\u7ed8\u5236\uff0c\u7c7b\u4f3c\u4e0b\u8fb9\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">PolygonShape(sides: 3).stroke(Color.blue, lineWidth: 3)\nPolygonShape(sides: 4).stroke(Color.purple, lineWidth: 4)\n<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"384\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-ad8e7c40dcb9bbff.png\" alt=\"\" class=\"wp-image-673\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-ad8e7c40dcb9bbff.png 694w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-ad8e7c40dcb9bbff-300x166.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-ad8e7c40dcb9bbff-230x127.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-ad8e7c40dcb9bbff-350x194.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-ad8e7c40dcb9bbff-480x266.png 480w\" sizes=\"(max-width: 694px) 100vw, 694px\" \/><\/figure><\/div>\n\n\n\n<p>\u5728\u5f00\u59cb\u7f16\u7801\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u7b80\u5355\u4ecb\u7ecd\u4e0b\u5b9e\u73b0\u8be5\u529f\u80fd\u9700\u8981\u7684\u4e00\u70b9\u4e09\u89d2\u51fd\u6570\u7684\u77e5\u8bc6\uff0c\u6211\u4e0d\u4f1a\u5728\u8fd9\u91cc\u505a\u8be6\u7ec6\u7684\u4ecb\u7ecd\uff0c<a rel=\"noreferrer noopener\" href=\"https:\/\/swiftui-lab.com\/trigonometric-recipes-for-swiftui\/\" target=\"_blank\">\u66f4\u8be6\u7ec6\u7684\u53ef\u4ee5\u70b9\u51fb\u8fd9\u91cc<\/a>\u3002<\/p>\n\n\n\n<p>\u6709\u4e00\u4e2a\u57fa\u672c\u5b9a\u7406\uff0c\u5728\u4e00\u4e2a\u5706\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u753b\u51fa\u4efb\u4f55n\u6b63\u8fb9\u5f62\uff0c\u8fd9\u4e00\u70b9\u5f88\u91cd\u8981\uff0c\u5728\u753b\u6b63\u8fb9\u5f62\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5148\u786e\u5b9a\u8be5\u6b63\u8fb9\u5f62\u5916\u5706\u7684\u534a\u5f84\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"351\" height=\"331\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-2ebe3c5d5bc70bf0.png\" alt=\"\" class=\"wp-image-677\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-2ebe3c5d5bc70bf0.png 351w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-2ebe3c5d5bc70bf0-300x283.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-2ebe3c5d5bc70bf0-230x217.png 230w\" sizes=\"(max-width: 351px) 100vw, 351px\" \/><\/figure><\/div>\n\n\n\n<p>\u6709\u4e86\u8fd9\u4e2a\u57fa\u672c\u6982\u5ff5\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u52a8\u624b\u6765\u5b9e\u73b0\u4e86\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"331\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-50ecc804fa2696af.png\" alt=\"\" class=\"wp-image-678\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-50ecc804fa2696af.png 735w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-50ecc804fa2696af-300x135.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-50ecc804fa2696af-230x104.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-50ecc804fa2696af-350x158.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-50ecc804fa2696af-480x216.png 480w\" sizes=\"(max-width: 735px) 100vw, 735px\" \/><\/figure><\/div>\n\n\n\n<ul><li>\u5706\u70b9\u7684\u4f4d\u7f6e\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\uff0c\u901a\u5e38\u662f\u56fe\u5f62\u7684\u4e2d\u5fc3\u70b9<\/li><li>\u534a\u5f84\u5f88\u597d\u8ba1\u7b97\uff0c\u6211\u4eec\u8981\u7ed8\u5236\u6b63\u8fb9\u5f62\u7684\u80cc\u666f\u901a\u5e38\u662f\u6b63\u65b9\u5f62\u6216\u8005\u957f\u65b9\u5f62\uff0c\u56e0\u6b64\u53d6\u6700\u77ed\u8fb9\u7684\u4e00\u534a\u4f5c\u4e3a\u534a\u5f84\u6bd4\u8f83\u5408\u9002<\/li><li>\u6b63\u8fb9\u5f62\u5404\u4e2a\u5b9a\u70b9\u5230\u5706\u70b9\u5f62\u6210\u7684\u5939\u89d2\u5f88\u597d\u8ba1\u7b97<\/li><\/ul>\n\n\n\n<p>\u6709\u70b9\u5706\u70b9\uff0c\u5939\u89d2\uff0c\u534a\u5f84\uff0c\u6211\u4eec\u5c31\u80fd\u591f\u786e\u5b9a\u6bcf\u4e2a\u5b9a\u70b9\u7684point\uff0c\u56e0\u6b64\u5c31\u80fd\u8f7b\u677e\u753b\u51fa\u6b63\u591a\u8fb9\u5f62\u7684path\u3002<strong>\u6211\u4eec\u8fd9\u4e9b\u4f8b\u5b50\u4e2d\u7684\u7b2c\u4e00\u4e2a\u9876\u70b9\u5728\u5706\u5fc3\u7684\u6b63\u53f3\u65b9\uff0c\u5e76\u4e0d\u662f\u4e0a\u56fe\u4e2d\u5bf9\u5e94\u7684\u4f4d\u7f6e\u3002<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u628a\u4e0a\u8fb9\u7684\u601d\u60f3\u5199\u6210\u4ee3\u7801\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct PolygonShape: Shape {\n    var sides: Int\n    \n    func path(in rect: CGRect) -> Path {        \n        \/\/ hypotenuse\n        let h = Double(min(rect.size.width, rect.size.height)) \/ 2.0\n        \n        \/\/ center\n        let c = CGPoint(x: rect.size.width \/ 2.0, y: rect.size.height \/ 2.0)\n        \n        var path = Path()\n                \n        for i in 0..&lt;sides {\n            let angle = (Double(i) * (360.0 \/ Double(sides))) * Double.pi \/ 180\n\n            \/\/ Calculate vertex position\n            let pt = CGPoint(x: c.x + CGFloat(cos(angle) * h), y: c.y + CGFloat(sin(angle) * h))\n            \n            if i == 0 {\n                path.move(to: pt) \/\/ move to first vertex\n            } else {\n                path.addLine(to: pt) \/\/ draw line to next vertex\n            }\n        }\n        \n        path.closeSubpath()\n        \n        return path\n    }\n}\n<\/pre>\n\n\n\n<p>\u73b0\u5728\u5927\u5bb6\u5e94\u8be5\u80fd\u591f\u6e05\u695a\u7684\u7406\u89e3\u4e0a\u8fb9\u4ee3\u7801\u7684\u5b9e\u73b0\u65b9\u5f0f\u4e86\u5427\uff1f\u7528\u8d77\u6765\u4e5f\u5f88\u7b80\u5355\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">PolygonShape(sides: isSquare ? 4 : 3)\n    .stroke(Color.blue, lineWidth: 3)\n    .animation(.easeInOut(duration: duration))\n<\/pre>\n\n\n\n<p>\u5f53\u6211\u4eec\u6539\u53d8<code>siders<\/code>\u7684\u65f6\u5019\uff0c\u4f60\u4ee5\u4e3a\u8fd9\u4e48\u7b80\u5355\u5c31\u80fd\u6307\u5b9a\u52a8\u753b\u4e86\uff1f \u8fd8\u662f\u592a\u5e74\u8f7b\u4e86\uff0c\u5b9e\u9645\u6548\u679c\u4e3a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"353\" height=\"331\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-c04261523bd9e84a.gif\" alt=\"\" class=\"wp-image-682\"\/><\/figure><\/div>\n\n\n\n<p>\u4f60\u89c9\u5f97SwiftUI\u662f\u600e\u6837\u5c06\u4e09\u89d2\u5f62\u8f6c\u5316\u6210\u56db\u8fb9\u5f62\u7684\uff0c\u7cfb\u7edf\u5176\u5b9e\u4e5f\u6ca1\u6709\u601d\u8def\u53bb\u505a\u52a8\u753b\uff0c\u4f60\u53ef\u80fd\u78b0\u5230\u52a8\u753b\u5c31.animation() \uff0c\u4f46\u662f\u8fd9\u91cc\u4e09\u89d2\u5f62\u53ea\u4f1a\u9a6c\u4e0a\u8df3\u5230\u56db\u8fb9\u5f62\u3002\u539f\u56e0\u5f88\u7b80\u5355\uff0cSwiftUI\u77e5\u9053\u5982\u4f55\u7ed8\u5236\u4e09\u89d2\u5f62\u548c\u56db\u8fb9\u5f62\uff0c\u4f46\u662f\u5b83\u4e0d\u77e5\u9053\u5982\u4f55\u7ed8\u52363.379\u8fb9\u5f62\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u505a2\u4ef6\u4e8b\u60c5\uff1a<\/p>\n\n\n\n<ul><li>\u6211\u4eec\u9700\u8981\u53bb\u6539\u53d8Shape\u76f8\u5173\u7684\u4ee3\u7801\uff0c\u56e0\u4e3a\u5b83\u77e5\u9053\u5982\u4f55\u7ed8\u5236\u975e\u6574\u6570\u8fb9\u5f62\u3002<\/li><li>\u8ba9\u7cfb\u7edf\u901a\u8fc7\u589e\u52a0\u53ef\u52a8\u53c2\u6570\u53bb\u591a\u6b21\u751f\u6210\u5f62\u72b6\uff0c\u6211\u4eec\u5e0c\u671b\u5f62\u72b6\u88ab\u7ed8\u5236\u591a\u6b21\uff0c\u6bcf\u6b21\u90fd\u6709\u4e0d\u540c\u7684\u8fb9\u6570\u503c:3, 3.1, 3.15, 3.2, 3.25 \u4e00\u76f4\u52304.<\/li><\/ul>\n\n\n\n<p>\u4e00\u65e6\u6211\u4eec\u505a\u5230\u4e86\u8fd9\u4e9b\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u505a\u5230\u4efb\u4f55\u8fb9\u6570\u4e2d\u95f4\u7684\u52a8\u753b\u5207\u6362\u3002<\/p>\n\n\n\n<p>\u60f3\u8ba9\u56fe\u5f62\u52a8\u8d77\u6765\uff0c\u6211\u4eec\u9700\u8981SwiftUI\u4f7f\u7528\u521d\u59cb\u503c\u5230\u6700\u7ec8\u503c\u4e4b\u95f4\u7684\u6240\u6709\u503c\u6765\u591a\u6b21\u6e32\u67d3\u89c6\u56fe\uff0c\u5e78\u8fd0\u7684\u662f\uff0c<code>Shape(\u56fe\u5f62)<\/code>\u5df2\u7ecf\u9075\u5b88\u4e86<code>Animatable<\/code>\u534f\u8bae\uff0c\u8fd9\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u7528\u5b83\u4eec\u7684\u8ba1\u7b97\u578b\u5c5e\u6027<code>animatableData<\/code>\u6765\u5904\u7406\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u89e3\u51b3\u6211\u4eec\u7684\u95ee\u9898\uff0c\u5148\u628aSides\u4eceInt\u6539\u6210Double\u7c7b\u578b\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u6709\u4e86\u5c0f\u6570\u7c7b\u578b\uff0c\u540e\u9762\u518d\u8ba8\u8bba\u600e\u4e48\u628a\u8fd9\u4e2a\u5c5e\u6027\u7ef4\u62a4\u6210Int\u7c7b\u578b\uff0c\u8fd8\u53ef\u4ee5\u505a\u52a8\u753b\uff0c\u8fd9\u91cc\u4e3a\u4e86\u7b80\u5355\u5148\u6539\u6210Double\u3002<\/p>\n\n\n\n<p>\u8fd9\u65f6\u5019\u6211\u4eec\u518d\u521b\u5efa\u8ba1\u7b97\u578b\u5c5e\u6027&nbsp;<strong>animatableData<\/strong>\uff0c \u8fd9\u91cc\u5c31\u5f88\u7b80\u5355\u4e86<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct PolygonShape: Shape {\n    var sides: Double\n\n    var animatableData: Double {\n        get { return sides }\n        set { sides = newValue }\n    }\n\n    ...\n}<\/pre>\n\n\n\n<p>\u90a3\u4e48\u95ee\u9898\u53c8\u6765\u4e86\uff0c\u5047\u8bbe\u6211\u4eec<code>siders<\/code>\u4ece3\u53d8\u4e3a4\uff0c\u7cfb\u7edf\u628a<code>siders<\/code>\u5206\u5272\u62103.1, 3.2, 3.3&#8230; 3.9, 4.0, \u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u5e94\u8be5\u5982\u4f55\u6839\u636e\u8fd9\u4e9b\u6570\u503c\u6765\u753b\u8def\u5f84\u5462\uff1f<\/p>\n\n\n\n<p>\u770b\u4e0b\u6838\u5fc3\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">func path(in rect: CGRect) -> Path {\n        \n        \/\/ hypotenuse\n        let h = Double(min(rect.size.width, rect.size.height)) \/ 2.0\n        \n        \/\/ center\n        let c = CGPoint(x: rect.size.width \/ 2.0, y: rect.size.height \/ 2.0)\n        \n        var path = Path()\n        \n        let extra: Int = Double(sides) != Double(Int(sides)) ? 1 : 0\n        \n        for i in 0..&lt;Int(sides) + extra {\n            let angle = (Double(i) * (360.0 \/ Double(sides))) * Double.pi \/ 180\n            \n            \/\/ Calculate vertex\n            let pt = CGPoint(x: c.x + CGFloat(cos(angle) * h), y: c.y + CGFloat(sin(angle) * h))\n            \n            if i == 0 {\n                path.move(to: pt) \/\/ move to first vertex\n            } else {\n                path.addLine(to: pt) \/\/ draw line to next vertex\n            }\n        }\n        \n        path.closeSubpath()\n        \n        return path\n    }<\/pre>\n\n\n\n<p><code>let extra: Int = Double(sides) != Double(Int(sides)) ? 1 : 0<\/code>\u8fd9\u884c\u4ee3\u7801\u4fdd\u8bc1\u4e86\u50cf3.4\u8fd9\u6837\u5927\u4e8e3\u7684\u6570\u80fd\u591f\u753b\u51fa4\u4e2a\u9876\u70b9\u3002<\/p>\n\n\n\n<p><code>for i in 0..&lt;Int(sides) + extra<\/code>\u8fd9\u91cc\u7684\u5faa\u73af\uff0c\u5faa\u73af\u591a\u5c11\u6b21\u5c31\u4f1a\u4ea7\u751f\u591a\u5c11\u7684\u9876\u70b9\uff0c\u8fd9\u4e00\u70b9\u5f88\u91cd\u8981\u3002<\/p>\n\n\n\n<p><code>let angle = (Double(i) * (360.0 \/ Double(sides))) * Double.pi \/ 180<\/code>,\u4e0d\u7ba1<code>siders<\/code>\u662f\u591a\u5c11\uff0c<code>(360.0 \/ Double(sides))<\/code>\u90fd\u662f\u76f8\u540c\u7684\u503c\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u6bcf\u6b21\u904d\u5386\u65cb\u8f6c\u7684\u89d2\u5ea6\u662f\u76f8\u540c\u7684\u3002<\/p>\n\n\n\n<p>SwiftUI\u89d2\u5ea6\u65cb\u8f6c\u662f\u987a\u65f6\u9488\u65b9\u5411\u7684\uff0c\u6c34\u5e73x\u8f74\u4e3a0\u5ea6\u3002\u6211\u4eec\u770b\u4e0b\u8fb9\u51e0\u4e2a\u622a\u56fe\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"329\" height=\"303\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-5b5963feb1675ce9.png\" alt=\"\" class=\"wp-image-688\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-5b5963feb1675ce9.png 329w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-5b5963feb1675ce9-300x276.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-5b5963feb1675ce9-230x212.png 230w\" sizes=\"(max-width: 329px) 100vw, 329px\" \/><\/figure><\/div>\n\n\n\n<p>\u4e0a\u8fb9\u8fd9\u5f20\u56fe\u662fsiders\u7b49\u4e8e3.2\u7684\u65f6\u5019\uff0c\u7ed8\u5236\u7684\u8def\u5f84\uff0c\u6211\u4eec\u5728\u8be5\u56fe\u7684\u57fa\u7840\u4e0a\u6dfb\u52a0\u4e00\u4e9b\u8bf4\u660e\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"329\" height=\"303\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-91a900a75b954ab9.png\" alt=\"\" class=\"wp-image-689\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-91a900a75b954ab9.png 329w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-91a900a75b954ab9-300x276.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-91a900a75b954ab9-230x212.png 230w\" sizes=\"(max-width: 329px) 100vw, 329px\" \/><\/figure><\/div>\n\n\n\n<p>\u7ed8\u56fe\u7684\u987a\u5e8f\u4e3a1 &gt; 2 &gt; 3 &gt; 4, \u89d21\uff0c\u89d22\uff0c \u89d23\u662f\u76f8\u540c\u7684\uff0c\u7ed8\u5236\u8fd9\u4e2a\u56fe\uff0cfor\u5faa\u73af\u4e864\u6b21\uff0c\u5927\u5bb6\u4ed4\u7ec6\u60f3\u60f3\uff0c\u8fd9\u91cc \u89d21\uff0c\u89d22\uff0c \u89d23\u76f8\u52a0\u4e0d\u7b49\u4e8e360\u5ea6\u662f\u6b63\u5e38\u7684\u3002<\/p>\n\n\n\n<p>\u5f88\u660e\u663e\uff0c\u5047\u8bbe\u5f53siders\u589e\u5927\u4e00\u70b9\u52303.4\u7684\u65f6\u5019\uff0c\u7531\u4e8e<code>(360.0 \/ Double(sides))<\/code>\u7684\u539f\u56e0\uff0c\u8fd9\u65f6\u5019\u89d21\uff0c\u89d22\uff0c \u89d23\u4f1a\u53d8\u5c0f\u4e00\u4e9b\uff0c\u6b63\u597d1\u548c4\u4e4b\u95f4\u7684\u7ebf\u6bb5\u4f1a\u589e\u957f\u4e00\u70b9\u3002\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"342\" height=\"292\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-4f793b96441e0dd8.png\" alt=\"\" class=\"wp-image-690\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-4f793b96441e0dd8.png 342w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-4f793b96441e0dd8-300x256.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2020\/08\/1914952-4f793b96441e0dd8-230x196.png 230w\" sizes=\"(max-width: 342px) 100vw, 342px\" \/><\/figure><\/div>\n\n\n\n<p>\u597d\u4e86\uff0c\u6211\u4eec\u5df2\u7ecf\u5206\u6790\u7684\u5f88\u8be6\u7ec6\u4e86\uff0c\u53ea\u9700\u8981\u589e\u52a0\u4e00\u70b9\u70b9\u4ee3\u7801\u5c31\u80fd\u52a8\u8d77\u6765\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct Example1PolygonShape: Shape {\n    var sides: Double\n    \n    var animatableData: Double {\n        get { return sides }\n        set { sides = newValue }\n    }\n    \n    func path(in rect: CGRect) -> Path {\n                ...\n    }\n}<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"353\" height=\"331\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-b3a4a751894dcf5e.gif\" alt=\"\" class=\"wp-image-692\"\/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eec\u5728\u4e0a\u8fb9\u7684\u57fa\u7840\u4e0a\u518d\u6269\u5c55\u4e00\u70b9\u4e1c\u897f\u51fa\u6765\uff0c\u5982\u679c\u6211\u60f3\u540c\u65f6\u6267\u884c2\u79cd\u52a8\u753b\uff0c\u90a3\u8be5\u5982\u4f55\u5462\uff1f \u5176\u5b9e\u975e\u5e38\u7b80\u5355\u3002<code>animatableData<\/code>\u53ea\u8981\u6c42set\u548cget\u5b9e\u73b0\u4e86<code>VectorArithmetic<\/code>\u534f\u8bae\u7684\u503c\u5c31\u884c\uff0c\u6211\u4eec\u4e0a\u8fb9\u7528\u5230\u7684<code>Double<\/code>\u5c31\u5b9e\u73b0\u4e86\uff0c\u5982\u679c\u6211\u4eec\u4e24\u540c\u65f6\u6267\u884c2\u79cd\u52a8\u753b\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528<code>AnimatablePair&lt;First, Second&gt;<\/code>\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct PolygonShape: Shape {\n    var sides: Double\n    var scale: Double\n    \n    var animatableData: AnimatablePair&lt;Double, Double> {\n        get { AnimatablePair(sides, scale) }\n        set {\n            sides = newValue.first\n            scale = newValue.second\n        }\n    }\n\n    ...\n}\n<\/pre>\n\n\n\n<p>\u7ed8\u5236\u8def\u5f84\u7684\u65b9\u6cd5\u4e5f\u53ea\u9700\u8981\u6539\u4e00\u70b9\u70b9\u5c31\u53ef\u4ee5\u4e86\uff0c\u5229\u7528<code>scale<\/code>\u8ba1\u7b97\u534a\u5f84\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">  func path(in rect: CGRect) -> Path {\n      let h = Double(min(rect.size.width, rect.size.height) \/ 2.0) * scale\n      ...\n  }<\/pre>\n\n\n\n<p>\u5982\u6b64\u7b80\u5355\uff0c\u518d\u770b\u4e0b\u6548\u679c\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"397\" height=\"394\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-3a63398fb12bbae9-1.gif\" alt=\"\" class=\"wp-image-695\"\/><\/figure><\/div>\n\n\n\n<p>\u4e5f\u8bb8\u4f60\u73b0\u5728\u6709\u4e86\u4e00\u4e2a\u65b0\u7684\u7591\u95ee\uff0c\u5982\u679c\u6211\u4eec\u540c\u65f6\u6267\u884c\u8d85\u8fc7\u4e24\u4e2a\u52a8\u753b\uff0c\u5e94\u8be5\u600e\u4e48\u529e\uff1f \u7b54\u6848\u4e5f\u540c\u6837\u5f88\u7b80\u5355: <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">AnimatablePair&lt;AnimatablePair&lt;CGFloat, CGFloat>, AnimatablePair&lt;CGFloat, CGFloat>>\n<\/pre>\n\n\n\n<p>\u57fa\u4e8e\u6b64\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5f15\u7533\u5230n\u4e2a\u503c\uff0c\u5728\u7cfb\u7edf\u4e2d<code>CGPoint<\/code>,<code>CGSize\u548c<\/code>\u548c<code>CGRect<\/code>\u90fd\u53ef\u4ee5\u6267\u884c\u52a8\u753b\uff0c\u662f\u56e0\u4e3a\u4ed6\u4eec\u90fd\u5b9e\u73b0\u4e86<code>Animatable<\/code>\u534f\u8bae\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">extension CGPoint : Animatable {\n    public typealias AnimatableData = AnimatablePair&lt;CGFloat, CGFloat>\n    public var animatableData: CGPoint.AnimatableData\n}\n\nextension CGSize : Animatable {\n    public typealias AnimatableData = AnimatablePair&lt;CGFloat, CGFloat>\n    public var animatableData: CGSize.AnimatableData\n}\n\nextension CGRect : Animatable {\n    public typealias AnimatableData = AnimatablePair&lt;CGPoint.AnimatableData, CGSize.AnimatableData>\n    public var animatableData: CGRect.AnimatableData\n}<\/pre>\n\n\n\n<p>\u5728\u8fd9\u4e00\u5c0f\u8282\u7684\u6700\u540e\uff0c\u6211\u4eec\u518d\u770b\u4e00\u4e2a\u66f4\u52a0\u9177\u70ab\u7684\u6548\u679c\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"198\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-d09916f7c4b730c9.gif\" alt=\"\" class=\"wp-image-697\"\/><\/figure><\/div>\n\n\n\n<p>\u5b9e\u73b0\u4e0a\u8fb9\u7684\u7684\u6548\u679c\u4e5f\u5f88\u7b80\u5355\u5c31\u662f\u7528\u4e0a\u8fb9\u7684\u65b9\u6cd5\u7ed8\u5236\u5b8c\u56fe\u5f62\u540e\uff0c\u518d\u8ba9\u6bcf\u4e2a\u9876\u70b9\u5206\u522b\u540c\u522b\u7684\u9876\u70b9\u8fde\u7ebf,\u6838\u5fc3\u4ee3\u7801\u4e3a\u51fd\u6570<code>drawVertexLines<\/code>\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">func path(in rect: CGRect) -> Path {\n        ...\n        \n        drawVertexLines(path: &amp;path, vertexs: vertex, n: 0)\n        \n        return path\n    }\n    \n    func drawVertexLines(path: inout Path, vertexs: [CGPoint], n: Int) {\n        if vertexs.count - n &lt; 3 {\n            return\n        }\n        \n        for i in (n+2)..&lt;min(n + vertexs.count - 1, vertexs.count) {\n            path.move(to: vertexs[n])\n            path.addLine(to: vertexs[i])\n        }\n        \n        drawVertexLines(path: &amp;path, vertexs: vertexs, n: n+1)\n    }<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">5.Making Your Own Type Animatable (with VectorArithmetic)<\/h4>\n\n\n\n<p>\u5728\u4e0a\u8fb9\u7684\u8fd9\u4e9b\u5c0f\u8282\u4e2d\uff0c\u6211\u4eec\u90fd\u4f7f\u7528\u4e86SwiftUI\u7cfb\u7edf\u63d0\u4f9b\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u8fd9\u4e9b\u7ed3\u6784\u8db3\u77e3\uff0c\u4f46\u6211\u4eec\u8fd8\u60f3\u5728\u6b64\u57fa\u7840\u4e4b\u4e0a\uff0c\u505a\u51fa\u4e00\u4e9b\u66f4\u52a0\u590d\u6742\u7684\u4e1c\u897f\u3002<\/p>\n\n\n\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6211\u4eec\u4eec\u60f3\u4f7f\u7528\u6211\u4eec\u81ea\u5b9a\u4e49\u7684struct\u6765\u505a\u52a8\u753b\uff0c\u53ea\u8981\u8bb2\u5230\u52a8\u753b\uff0c\u5c31\u79bb\u4e0d\u5f00\u4e00\u4e2a\u503c\u4ece\u67d0\u4e00\u4e2a\u503c\u5230\u53e6\u4e00\u4e2a\u503c\u7684\u53d8\u5316\uff0c\u6211\u4eec\u8fd9\u4e2a\u4f8b\u5b50\u5c31\u662f\u65f6\u949f\u7684\u4e00\u4e2a\u52a8\u753b\uff0c\u5148\u770b\u4e0b\u6700\u540e\u7684\u6548\u679c\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"204\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-b2e1f807ce948d2b.gif\" alt=\"\" class=\"wp-image-699\"\/><\/figure><\/div>\n\n\n\n<p>\u8981\u60f3\u63cf\u8ff0\u67d0\u4e00\u523b\u7684\u65f6\u95f4\uff0c\u6211\u4eec\u9700\u89813\u4e2a\u5c5e\u6027\uff0c\u65f6\uff0c\u5206\uff0c\u79d2\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u628a\u5b83\u4eec\u5c01\u88c5\u5230\u4e00\u4e2a\u7ed3\u6784\u4f53\u4e2d\uff0c\u5f53\u9700\u8981\u5207\u6362\u65f6\u95f4\u7684\u65f6\u5019\uff0c\u76f4\u63a5\u5728\u53d8\u5316\u7684\u4e24\u4e2a\u7ed3\u6784\u4f53\u4e2d\u95f4\u63d2\u503c\u3002<\/p>\n\n\n\n<p>\u5c0f\u63d0\u793a\uff1a<code>Angle<\/code>, <code>CGPoint<\/code>, <code>CGRect<\/code>, <code>CGSize<\/code>, <code>EdgeInsets<\/code>, <code>StrokeStyle<\/code> \u548c <code>UnitPoint<\/code>\uff0c\u8fd9\u4e9b\u90fd\u5b9e\u73b0\u4e86<code>Animatable<\/code>\u534f\u8bae\uff0c<code>AnimatablePair<\/code>, <code>CGFloat<\/code>, <code>Double<\/code>, <code>EmptyAnimatableData<\/code> \u548c <code>Float<\/code>\uff0c\u8fd9\u4e9b\u90fd\u5b9e\u73b0\u4e86<code>VectorArithmetic<\/code>\u534f\u8bae\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u5148\u5199<code>ClockTime<\/code>\u7ed3\u6784\u4f53\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct ClockTime {\n    var hours: Int\n    var minutes: Int\n    var seconds: Double\n    \n    init(_ h: Int, _ m: Int, _ s: Double) {\n        self.hours = h\n        self.minutes = m\n        self.seconds = s\n    }\n    \n    init(_ seconds: Double) {\n        let hours = Int(seconds) \/ 3600\n        let minutes = (Int(seconds) - (hours * 3600)) \/ 60\n        let seconds = seconds - Double(hours * 3600) - Double(minutes * 60)\n        \n        self.hours = hours\n        self.minutes = minutes\n        self.seconds = seconds\n    }\n    \n    func asSeconds() -> Double {\n        return Double(self.hours * 3600) + Double(self.minutes * 60) + self.seconds\n    }\n    \n    func asString() -> String {\n        return String(format: \"%2i\", self.hours) +\n            \" : \" +\n            String(format: \"%02i\", self.minutes) +\n            \" : \" +\n            String(format: \"%02.0f\", self.seconds)\n    }\n}<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u7684\u4ee3\u7801\u975e\u5e38\u7b80\u5355\uff0c\u5c31\u662f\u521d\u59cb\u5316\u548c\u4e00\u4e9b\u51fd\u6570\uff0c\u5927\u5bb6\u5e94\u8be5\u80fd\u591f\u7406\u89e3\uff0c\u5982\u679c\u8981\u5bf9<code>ClockTime<\/code>\u505a\u52a0\u51cf\u6cd5\uff0c\u5176\u5b9e\u90fd\u662f\u5bf9\u4e24\u4e2a\u65f6\u95f4\u7684\u603b\u79d2\u6570\u505a\u52a0\u51cf\u6cd5\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u8ba9<code>ClockTime<\/code>\u5b9e\u73b0<code>VectorArithmetic<\/code>\u534f\u8bae\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">extension ClockTime: VectorArithmetic {\n    static func - (lhs: ClockTime, rhs: ClockTime) -> ClockTime {\n        return ClockTime(lhs.asSeconds() - rhs.asSeconds())\n    }\n    \n    static func + (lhs: ClockTime, rhs: ClockTime) -> ClockTime {\n        return ClockTime(lhs.asSeconds() + rhs.asSeconds())\n    }\n    \n    mutating func scale(by rhs: Double) {\n        var s = Double(self.asSeconds())\n        s.scale(by: rhs)\n        \n        let time = ClockTime(s)\n        self.hours = time.hours\n        self.minutes = time.minutes\n        self.seconds = time.seconds\n    }\n    \n    var magnitudeSquared: Double {\n        1\n    }\n    \n    static var zero: ClockTime {\n        ClockTime(0, 0, 0)\n    }\n}<\/pre>\n\n\n\n<p>\u5176\u5b9e\uff0c\u7c7b\u4f3c\u4e0a\u8fb9\u7684\u4ee3\u7801\uff0c\u57fa\u672c\u4e0a\u7b97\u662f\u56fa\u5b9a\u5199\u6cd5\uff0c\u4f46\u53ef\u4ee5\u53d1\u73b0\u4e00\u4e9b\u65b0\u7684\u60f3\u6cd5\uff0cSwiftUI\u7cfb\u7edf\u5185\u90e8\u5728\u505a\u63d2\u503c\u7684\u65f6\u5019\uff0c\u4f1a\u7528\u5230<code>VectorArithmetic<\/code>\u534f\u8bae\u4e2d\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>\u5173\u4e8e\u56fe\u5f62\u7ed8\u5236\u65b9\u9762\uff0c\u8fd8\u662f\u4e0a\u8fb9\u7684\u90a3\u4e00\u5957\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct ClockShape: Shape {\n    var time: ClockTime\n    \n    var animatableData: ClockTime {\n        get {\n            time\n        }\n        set {\n            time = newValue\n        }\n    }\n    \n    func path(in rect: CGRect) -> Path {\n        var path = Path()\n        \n        let radius = min(rect.size.width \/ 2.0, rect.size.height \/ 2.0)\n        let center = CGPoint(x: rect.size.width \/ 2.0, y: rect.size.height \/ 2.0)\n        \n        let hHypotenuse = Double(radius) * 0.5\n        let mHypotenuse = Double(radius) * 0.6\n        let sHypotenuse = Double(radius) * 0.8\n        \n        let hAngle: Angle = .degrees(Double(time.hours) \/ 12 * 360 - 90)\n        let mAngle: Angle = .degrees(Double(time.minutes) \/ 60 * 360 - 90)\n        let sAngle: Angle = .degrees(Double(time.seconds) \/ 60 * 360 - 90)\n        \n        let hoursNeedle = CGPoint(x: center.x + CGFloat(hHypotenuse * cos(hAngle.radians)), y: center.y + CGFloat(hHypotenuse * sin(hAngle.radians)))\n        let minutesNeedle = CGPoint(x: center.x + CGFloat(mHypotenuse * cos(mAngle.radians)), y: center.y + CGFloat(mHypotenuse * sin(mAngle.radians)))\n        let secondsNeedle = CGPoint(x: center.x + CGFloat(sHypotenuse * cos(sAngle.radians)), y: center.y + CGFloat(sHypotenuse * sin(sAngle.radians)))\n        \n        \/\/\/ \u753b\u5706\n        path.addArc(center: center, radius: radius,\n                    startAngle: .degrees(0), endAngle: .degrees(360),\n                    clockwise: true)\n        \n        \/\/\/ \u8868\u76d8\u523b\u5ea6\n        let numberLength: CGFloat = 5.0\n        let numberPadding: CGFloat = 12.0\n        let centerToNumber: CGFloat = radius - numberLength - numberPadding\n        \n        \n        for i in 0..&lt;12 {\n            let angle: Angle = .degrees(360.0 \/ 12.0 * Double(i))\n\n            let inPt = CGPoint(x: center.x + centerToNumber * CGFloat(cos(angle.radians)), y: center.y - centerToNumber * CGFloat(sin(angle.radians)))\n\n            let outPt = CGPoint(x: center.x + (centerToNumber + numberLength) * CGFloat(cos(angle.radians)), y: center.y - (centerToNumber + numberLength) * CGFloat(sin(angle.radians)))\n\n            path.move(to: inPt)\n            path.addLine(to: outPt)\n        }\n        \n        \n        \/\/\/ \u65f6\u9488\n        path.move(to: center)\n        path.addLine(to: hoursNeedle)\n        path = path.strokedPath(StrokeStyle(lineWidth: 3, lineCap: .round))\n        \n        \/\/\/ \u5206\u9488\n        path.move(to: center)\n        path.addLine(to: minutesNeedle)\n        path = path.strokedPath(StrokeStyle(lineWidth: 3, lineCap: .round))\n        \n        \/\/\/ \u79d2\u9488\n        path.move(to: center)\n        path.addLine(to: secondsNeedle)\n        path = path.strokedPath(StrokeStyle(lineWidth: 1, lineCap: .round))\n\n        return path\n    }\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">6.SwiftUI + Metal<\/h4>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u60f3\u5728SwiftUI\u4e2d\u5b9e\u73b0\u7279\u522b\u590d\u6742\u7684\u52a8\u753b\uff0c\u5e76\u5728\u771f\u673a\u4e0a\u8fd0\u884c\uff0c\u53ef\u80fd\u4f1a\u53d1\u73b0\uff0c\u52a8\u753b\u4e0d\u4e00\u5b9a\u90a3\u4e48\u6d41\u7545\uff0c\u8fd9\u79cd\u60c5\u51b5\u6bd4\u8f83\u9002\u5408\u5f00\u542fMetal\uff0c\u5f00\u542fMetal\u975e\u5e38\u7b80\u5355\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">FlowerView().drawingGroup()\n<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>According to WWDC 2019, Session 237 (<a rel=\"noreferrer noopener\" href=\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fdeveloper.apple.com%2Fvideos%2Fplay%2Fwwdc2019%2F237%2F\" target=\"_blank\">Building Custom Views with SwiftUI<\/a>): A drawing group is a special way of rendering but only for things like graphics. It will basically flatten the SwiftUI view into a single NSView\/UIView and render it with metal. Jump the WWDC video to 37:27 for a little more detail.<\/p><\/blockquote>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-e81214e138d8d156-1.gif\" alt=\"\" class=\"wp-image-803\" width=\"384\" height=\"210\"\/><\/figure><\/div>\n\n\n\n<p>\u53ef\u4ee5\u770b\u4e0b\u4e0a\u56fe\u7684\u6548\u679c\uff0c\u5f00\u542f\u4e86Metal\u540e\u6d41\u7545\u4e86\u5f88\u591a\u3002\u81f3\u4e8e\u4ee3\u7801\uff0c\u6211\u4eec\u8fd9\u91cc\u5c31\u4e0d\u7c98\u8d34\u4e86\uff0c\u5927\u5bb6\u53ef\u4ee5\u53bb\u539f\u4f5c\u8005\u7f51\u7ad9\u53bb\u770b\uff0c\u4e0a\u56fe\u4e2d\u6574\u4e2a\u56fe\u5f62\u662f\u65cb\u8f6c\u7684\uff0c\u4f46\u662f\u82b1\u74e3\u5e76\u6ca1\u6709\u505a\u989d\u5916\u7684\u65cb\u8f6c\uff0c\u800c\u662f\u63a7\u5236\u4e86\u7ed8\u5236\u82b1\u74e3\u7684\u5bbd\u5ea6\u6765\u5b9e\u73b0\u7684\uff0c\u8fd9\u6709\u52a9\u4e8e\u5927\u5bb6\u7406\u89e3\u4ee3\u7801\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u603b\u7ed3<\/h4>\n\n\n\n<p>SwiftUI\u52a8\u753b\u7684\u672c\u8d28\u5c31\u662f\u63d2\u503c\uff0c\u51e1\u662f\u5b9e\u73b0\u4e86<code>Animatable<\/code>\u534f\u8bae\u7684\u5bf9\u8c61\uff0c\u7cfb\u7edf\u5c31\u77e5\u9053\u5982\u4f55\u6267\u884c\u52a8\u753b\uff0c\u8fd9\u662f\u4e00\u4e2a\u6838\u5fc3\u601d\u60f3\u3002<\/p>\n\n\n\n<p>*\u6ce8\uff1a\u4e0a\u8fb9\u7684\u5185\u5bb9\u53c2\u8003\u4e86\u7f51\u7ad9<a rel=\"noreferrer noopener\" href=\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fswiftui-lab.com%2Fswiftui-animations-part1%2F\" target=\"_blank\">https:\/\/swiftui-lab.com\/swiftui-animations-part1\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u9996\u5148\u4e86\u89e3\u4e00\u4e2a\u6982\u5ff5\uff1a\u663e\u5f0f\u548c\u9690\u5f0f\u52a8\u753b SwiftUI\u4e2d\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u52a8\u753b\uff0c\u663e\u5f0f\u548c\u9690\u5f0f\u3002 \u9690\u5f0f\u52a8\u753b\u6307\u7684\u5c31\u662f\u7528.an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/657"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=657"}],"version-history":[{"count":43,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions"}],"predecessor-version":[{"id":804,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions\/804"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}