{"id":807,"date":"2020-08-15T23:50:49","date_gmt":"2020-08-15T15:50:49","guid":{"rendered":"http:\/\/123.57.164.21\/?p=807"},"modified":"2020-08-15T23:51:54","modified_gmt":"2020-08-15T15:51:54","slug":"swiftui-transitions","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=807","title":{"rendered":"SwiftUI Transitions"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Transition\u662f\u4ec0\u4e48\uff1f<\/h4>\n\n\n\n<p>\u5728SwiftUI\u4e2d\uff0ctransition\u51b3\u5b9a\u4e86\u67d0\u4e2aView\u5982\u4f55\u63d2\u5165\u5230\u89c6\u56fe\u6808\u4e2d\uff0c\u6216\u8005\u5982\u4f55\u5728\u89c6\u56fe\u6808\u4e2d\u79fb\u9664\u3002transition\u81ea\u8eab\u5e76\u6ca1\u6709\u4efb\u4f55\u6548\u679c\uff0c \u9700\u8981\u914d\u5408\u52a8\u753b\u4e00\u8d77\u4f7f\u7528\uff0c\u4e3e\u4e2a\u4f8b\u5b50\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 show = false\n    \n    var body: some View {\n        VStack {\n            Spacer()\n            \n            if show {\n                LabelView()\n                    .transition(.opacity)\n            }\n            \n            Spacer()\n            \n            Button(\"\u70b9\u51fb\") {\n                self.show.toggle()\n            }\n            .padding(20)\n        }\n    }\n}<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"223\" height=\"146\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-7562e32064159bd9-1.gif\" alt=\"\" class=\"wp-image-809\"\/><\/figure><\/div>\n\n\n\n<p>\u53ef\u4ee5\u770b\u51fa\uff0c\u5e76\u6ca1\u6709\u4ec0\u4e48\u52a8\u753b\u6548\u679c\uff0c\u5176\u5b9e\uff0c\u8fd9\u4e5f\u5f88\u597d\u7406\u89e3\uff0ctransition\u53ea\u662f\u544a\u8bc9\u7cfb\u7edf\u8bd5\u56fe\u5982\u4f55\u8fc7\u6e21\uff0c\u7cfb\u7edf\u5e76\u4e0d\u77e5\u9053\u8fc7\u6e21\u7684\u52a8\u753b\u51fd\u6570\u662f\u4ec0\u4e48\uff0c\u4e5f\u5c31\u65e0\u6cd5\u505a\u52a8\u753b\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f\uff0c\u5373\u4f7f\u4f7f\u7528\u9690\u5f0f\u52a8\u753b\uff0c\u4e5f\u5c31\u662f<code>.animation()<\/code> modifier\u4e5f\u4e0d\u8d77\u4f5c\u7528\u3002<\/strong>\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 show = false\n    \n    var body: some View {\n        VStack {\n            Spacer()\n            \n            if show {\n                LabelView()\n                        .animation(.easeInOut)\n                    .transition(.opacity)\n            }\n                    ...\n    }\n}<\/pre>\n\n\n\n<p><strong>\u8981\u60f3\u8ba9transition\u6709\u52a8\u753b\uff0c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<ul><li>\u7b2c\u4e00\u79cd\u662f\u7ed9\u51fa\u4e00\u4e2a\u663e\u5f0f\u52a8\u753b\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/li><\/ul>\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 show = false\n    \n    var body: some View {\n        VStack {\n                        ...\n            \n            Button(\"\u70b9\u51fb\") {\n                withAnimation(.easeInOut(duration: 1.0)) {\n                    self.show.toggle()\n                }\n            }\n            .padding(20)\n        }\n    }\n}<\/pre>\n\n\n\n<ul><li>\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u4e3atransition\u5173\u8054\u4e00\u4e2a\u52a8\u753b\uff0c<strong>\u8fd9\u91cc\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4eec\u4e0b\u8fb9\u4ee3\u7801\u4e2d\u4e0etransition\u5173\u8054\u7684\u52a8\u753b\u4f5c\u7528\u4e8etransition\uff0c\u5e76\u4e0d\u662f\u4f5c\u7528\u4e8eview\u7684\u3002<\/strong><\/li><\/ul>\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 show = false\n    \n    var body: some View {\n        VStack {\n            Spacer()\n            \n            if show {\n                LabelView()\n                    .transition(AnyTransition.opacity.animation(.easeInOut(duration: 1.0)))\n            }\n            \n            Spacer()\n            \n            Button(\"\u70b9\u51fb\") {\n                self.show.toggle()\n            }\n            .padding(20)\n        }\n    }\n}<\/pre>\n\n\n\n<p>\u6dfb\u52a0\u4e86\u52a8\u753b\u7684\u6548\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"223\" height=\"146\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-a3e229802eb61b51.gif\" alt=\"\" class=\"wp-image-810\"\/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">\u975e\u5bf9\u79f0\u7684Transitions<\/h4>\n\n\n\n<p>\u5728\u4e86\u89e3\u4ec0\u4e48\u53eb\u975e\u5bf9\u79f0\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u4e86\u89e3\u4e00\u4e0b\u5bf9\u79f0\uff0c\u5bf9\u4e8etransition\u6765\u8bf4\uff0c\u5f53view\u51fa\u73b0\u7684\u65f6\u5019\uff0c\u4f1a\u6267\u884c\u67d0\u4e2a\u8fc7\u6e21\u6548\u679c\uff0c\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5f53\u8be5view\u6d88\u5931\u7684\u65f6\u5019\uff0c\u4f1a\u6267\u884c\u4e0e\u51fa\u73b0\u76f8\u53cd\u7684\u8fc7\u6e21\u6548\u679c\uff0c\u8fd9\u5c31\u662ftransiton\u7684\u5bf9\u79f0\u6027\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"430\" height=\"146\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-b6253f765fcd2a8d.gif\" alt=\"\" class=\"wp-image-812\"\/><\/figure><\/div>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u7eff\u8272\u6587\u672c\u4ece\u5de6\u8fb9\u6ed1\u5165\uff0c\u7136\u540e\u4ece\u53f3\u8fb9\u6ed1\u51fa\uff0c\u662f\u4e00\u4e2a\u5bf9\u79f0\u7684\u8fc7\u6e21\u6548\u679c\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>.asymmetric<\/code>\u6765\u5b9e\u73b0\u975e\u5bf9\u79f0\u7684\u8fc7\u6e21\u6548\u679c\uff0c\u4ee3\u7801\u5982\u4e0b:<\/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=\"\">.transition(.asymmetric(insertion: .opacity, removal: .scale))\n\n<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"430\" height=\"146\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-a21621e8ee93bedd.gif\" alt=\"\" class=\"wp-image-813\"\/><\/figure><\/div>\n\n\n\n<p>\u53ef\u4ee5\u770b\u51fa\uff0c\u51fa\u73b0\u548c\u6d88\u5931\u4f7f\u7528\u4e86\u4e0d\u540c\u7684\u8fc7\u6e21\u6548\u679c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7ec4\u5408Transitions<\/h4>\n\n\n\n<p>\u6211\u4eec\u8fd8\u60f3\u66f4\u8fdb\u4e00\u6b65\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7ec4\u5408\u6765\u4e3a\u67d0\u4e2a\u8fc7\u6e21\u6548\u679c\u5b9e\u73b0\u591a\u4e2a\u52a8\u753b\u8fc7\u7a0b\uff0c\u5728SwiftUI\u4e2d\u7684\u5b9e\u73b0\u4ee3\u7801\u4e5f\u8d85\u7ea7\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=\"\">.transition(AnyTransition.opacity.combined(with: .slide))\n\n<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"430\" height=\"146\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-50e73d7e4c153cdc.gif\" alt=\"\" class=\"wp-image-814\"\/><\/figure><\/div>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u7eff\u8272\u6587\u672c\u7684\u8fc7\u6e21\u52a8\u753b\uff0c\u901a\u77e5\u6267\u884c\u4e86<code>opacity<\/code>\u548c<code>slide<\/code>\u4e24\u79cd\u6548\u679c\uff0c\u5f53\u7136\u6211\u4eec\u4e5f\u53ef\u4ee5\u5728<code>asymmetric<\/code>\u4e2d\u4f7f\u7528\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=\"\">.transition(.asymmetric(insertion: AnyTransition.opacity.combined(with: .slide), removal: AnyTransition.scale.combined(with: .slide)))\n<\/pre>\n\n\n\n<p>\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=\"430\" height=\"146\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-89c283e36733d42a.gif\" alt=\"\" class=\"wp-image-815\"\/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">\u5e26\u6709\u53c2\u6570\u7684Transitions<\/h4>\n\n\n\n<p>\u6211\u4eec\u5728\u4e0a\u8fb9\u7684\u4ee3\u7801\u4e2d\uff0c\u53ea\u4f7f\u7528\u4e86\u7c7b\u4f3c<code>.slide<\/code>\u8fd9\u6837\u7684\u53c2\u6570\uff0c\u5176\u5b9e\u8fd9\u4e9b\u53c2\u6570\u8fd8\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e9b\u989d\u5916\u7684\u53c2\u6570\uff0c\u4f8b\u5982\u4e0b\u8fb9\u8fd9\u4e9b\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=\"\">.scale(scale: 0.0, anchor: UnitPoint(x: 1, y: 0))\n.scale(scale: 2.0)\n.move(edge: .leading)\n.offset(x: 30)\n.offset(y: 50)\n.offset(x: 100, y: 10)\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">\u81ea\u5b9a\u4e49Transitions<\/h4>\n\n\n\n<p>\u672c\u7bc7\u6587\u7ae0\u7684\u6838\u5fc3\u5185\u5bb9\u6765\u4e86\uff0c\u4e0a\u8fb9\u4ecb\u7ecd\u7684\u5404\u79cd\u6548\u679c\u57fa\u672c\u4e0a\u80fd\u591f\u6ee1\u8db3\u6211\u4eec\u5927\u90e8\u5206\u7684\u5f00\u53d1\u9700\u6c42\uff0c\u4f46\u662f\uff0c\u603b\u6709\u4f8b\u5916\uff0c\u5f53\u6211\u4eec\u9700\u8981\u590d\u6742\u7684\u8fc7\u6e21\u6548\u679c\u7684\u65f6\u5019\uff0c\u8fd9\u4e00\u5c0f\u8282\u7684\u5185\u5bb9\u80fd\u591f\u7ed9\u4f60\u63d0\u4f9b\u66f4\u591a\u7684\u601d\u8def<\/p>\n\n\n\n<p><strong>\u6bd4\u5982\uff0c \u5728App\u4e2d\u7684\u5404\u79cd\u6837\u5f0f\u7684\u5f39\u5c4f\uff0c\u7ffb\u9875\u7b49\u7b49\uff0c\u4f60\u80fd\u60f3\u5230\u7684\u8fc7\u6e21\u90fd\u5c5e\u4e8eTransitions\u7684\u8303\u7574\u3002<\/strong>\u5f53\u7136\u6211\u4eec\u8fd9\u91cc\u53ea\u662f\u6f14\u793a\u4e86\u81ea\u5b9a\u4e49\u8fd9\u4e9b\u8fc7\u6e21\u6548\u679c\u7684\u6838\u5fc3\u601d\u60f3\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u5148\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6211\u4eec\u81ea\u5b9a\u4e49\u4e00\u4e2a\u8fc7\u6e21\u6548\u679c\uff0c\u7c7b\u4f3c\u4e0e\u4e0a\u8fb9\u7528\u5230\u7684<code>opacity<\/code>\u6548\u679c\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=\"\">extension AnyTransition {\n    static var myCustomOpacity: AnyTransition {\n        AnyTransition.modifier(active: MyOpacityModifier(opacity: 0), identity: MyOpacityModifier(opacity: 1))\n    }\n}\n\nstruct MyOpacityModifier: ViewModifier {\n    let opacity: Double\n    \n    func body(content: Content) -> some View {\n        content.opacity(opacity)\n    }\n}<\/pre>\n\n\n\n<ul><li>\u5199\u4e00\u4e2a<code>AnyTransition<\/code>\u7684\u6269\u5c55<\/li><li>\u5b9e\u73b0\u4e00\u4e2a<code>myCustomOpacity<\/code>\u7684\u9759\u6001\u7c7b\u578b<\/li><li>\u8fd4\u56de\u503c\u4e3a<code>AnyTransition.modifier<\/code>\uff0c\u5b83\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff0c<code>active<\/code>\u548c<code>identity<\/code>\uff0c\u5206\u522b\u8868\u793a\u5f00\u59cb\u548c\u7ed3\u675f<\/li><li><code>active<\/code>\u548c<code>identity<\/code>\u662f\u4e2a<code>ViewModifier<\/code>\u7c7b\u578b<\/li><\/ul>\n\n\n\n<p>\u57fa\u672c\u4e0a\u5c31\u8fd9\u51e0\u6b65\uff0c\u7136\u540e\u6211\u4eec\u8fd9\u4e48\u4f7f\u7528\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=\"\">.transition(.myCustomOpacity)\n\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"223\" height=\"146\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/08\/1914952-d55853c89ce68f82.gif\" alt=\"\" class=\"wp-image-819\"\/><\/figure>\n\n\n\n<p><strong>\u5927\u5bb6\u4ed4\u7ec6\u770b\u4e0a\u8fb9\u7684\u4ee3\u7801\uff0c\u7531\u4e8e\u672c\u8d28\u4e0a\u662f\u4e2a<code>ViewModifier<\/code>\uff0c\u76f8\u5f53\u4e8e\u4fee\u6539\u4e86view\u7684<code>opacity<\/code>\uff0c\u8fd9\u4e5f\u5c31\u662f\u6211\u4eec\u4e0a\u8fb9\u8bf4\u8fc7\u7684\uff0c\u4e0d\u52a0\u663e\u5f0f\u52a8\u753b\uff0c\u4e0d\u4f1a\u4ea7\u751f\u8fc7\u6e21\u6548\u679c\u7684\u539f\u56e0\u3002<\/strong><\/p>\n\n\n\n<p>\u6709\u5f88\u591a\u52a8\u753b\u6548\u679c\uff0c\u6bd4\u5982<code>.rotationEffect()<\/code> \u548c<code>.transformEffect()<\/code>\uff0c\u7528transition\u90fd\u53ef\u4ee5\u5b9e\u73b0\uff0c\u6211\u4eec\u5728\u6700\u540e\uff0c\u4f7f\u7528<code>GeometryEffect<\/code>\u6765\u5b9e\u73b0\u4e00\u4e2a\u4e0b\u8fb9\u8fd9\u6837\u7684\u6548\u679c\uff1a<\/p>\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-55b05fc39d6b46d6-min.gif\" alt=\"\" class=\"wp-image-821\" width=\"284\" height=\"413\"\/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eec\u5148\u8bb2\u4e00\u4e0b\u8be5\u52a8\u753b\u7684\u5b9e\u73b0\u601d\u8def\uff1a<\/p>\n\n\n\n<ul><li>\u51fa\u73b0\u7684\u65f6\u5019\uff0c\u4e00\u8fb9\u7f29\u653e\uff0c\u4e00\u8fb9\u65cb\u8f6c<\/li><li>\u4ed4\u7ec6\u89c2\u5bdf\uff0c\u7f29\u653e\u52a8\u753b\u5728\u6574\u4e2a\u52a8\u753b\u65f6\u95f4\u7684\u4e00\u534a\u7684\u65f6\u5019\uff0c\u5c31\u5df2\u7ecf\u7f29\u653e\u5b8c\u6bd5<\/li><li>\u65cb\u8f6c\u6cbf\u7740x\u8f74<\/li><\/ul>\n\n\n\n<p>\u6709\u4e86\u4e0a\u8fb9\u7684\u601d\u8def\u540e\uff0c\u6211\u4eec\u518d\u770b\u4e0b\u8fb9\u7684\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 GeometryEffectTransitionsDemo: View {\n    @State private var show = false\n    \n    var body: some View {\n        \n        return ZStack {\n            Button(\"Open Booking\") {\n                withAnimation(.easeInOut(duration: 0.8)) {\n                    self.show.toggle()\n                }\n            }.position(x: 100, y: 20)\n            \n            if show {\n                RoundedRectangle(cornerRadius: 15)\n                    .fill(Color.green)\n                    .frame(width: 300, height: 400)\n                    .shadow(color: .black, radius: 3)\n                    .transition(.fly)\n                    .zIndex(1)\n            }\n        }\n    }\n}\n\nextension AnyTransition {\n    static var fly: AnyTransition {\n        AnyTransition.modifier(active: FlyModifier(pct: 0), identity: FlyModifier(pct: 1))\n    }\n}\n\nstruct FlyModifier: GeometryEffect {\n    var pct: Double\n    \n    var animatableData: Double {\n        get {\n            pct\n        }\n        set {\n            pct = newValue\n        }\n    }\n    \n    func effectValue(size: CGSize) -> ProjectionTransform {\n        let a = CGFloat(Angle(degrees: 90 * (1 - pct)).radians)\n        \n        var transform3d = CATransform3DIdentity\n        transform3d.m34 = -1 \/ max(size.width, size.height)\n        \n        transform3d = CATransform3DRotate(transform3d, a, 1, 0, 0)\n        transform3d = CATransform3DTranslate(transform3d, -size.width \/ 2.0, -size.width \/ 2.0, 0)\n        \n        let afffineTransform1 = ProjectionTransform(CGAffineTransform(translationX: size.width \/ 2.0, y: size.width \/ 2.0))\n        let afffineTransform2 = ProjectionTransform(CGAffineTransform(scaleX: CGFloat(pct * 2), y: CGFloat(pct * 2)))\n        \n        if pct &lt;= 0.5 {\n            return ProjectionTransform(transform3d).concatenating(afffineTransform2).concatenating(afffineTransform1)\n        } else {\n            return ProjectionTransform(transform3d).concatenating(afffineTransform1)\n        }\n    }\n}<\/pre>\n\n\n\n<p><code>GeometryEffect<\/code>\u672c\u8eab\u5373\u5b9e\u73b0\u4e86<code>ViewModifier<\/code>\u534f\u8bae\uff0c\u53c8\u5b9e\u73b0\u4e86<code>Animatable<\/code>\u534f\u8bae\uff0c\u56e0\u6b64\u5b83\u53ef\u4ee5\u4f5c\u4e3a<code>active<\/code>\u548c<code>identity<\/code>\u7684\u53c2\u6570\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7<code>animatableData<\/code>\u83b7\u53d6\u52a8\u753b\u72b6\u6001\u3002<\/p>\n\n\n\n<p>\u6574\u4e2a\u8fc7\u6e21\u6548\u679c\u7684\u6838\u5fc3\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 effectValue(size: CGSize) -> ProjectionTransform {\n      ...\n        if pct &lt;= 0.5 {\n            return ProjectionTransform(transform3d).concatenating(afffineTransform2).concatenating(afffineTransform1)\n        } else {\n            return ProjectionTransform(transform3d).concatenating(afffineTransform1)\n        }\n    }<\/pre>\n\n\n\n<p>\u6211\u4eec\u7528pct\u8ddf0.5\u505a\u5224\u65ad\uff0c\u8fd4\u56de\u4e0d\u540c\u7684\u5f62\u53d8\u503c\uff0c\u5c31\u5b9e\u73b0\u4e86\u4e0a\u8fb9\u7684\u6548\u679c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">\u603b\u7ed3<\/h4>\n\n\n\n<p>\u5f53\u6211\u4eec\u8003\u8651\u4e3a\u67d0\u4e2aView\u4f7f\u7528\u8fc7\u6e21\u52a8\u753b\u7684\u65f6\u5019\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u8003\u8651Transitions\u4e86\uff0cTransitions\u5f3a\u5927\u7684\u81ea\u5b9a\u4e49\u529f\u80fd\u80fd\u591f\u8ba9\u6211\u4eec\u5b9e\u73b0\u5f88\u591a\u590d\u6742\u7684UI\u6548\u679c\u3002<\/p>\n\n\n\n<p><em>\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%2Fadvanced-transitions%2F\" target=\"_blank\">https:\/\/swiftui-lab.com\/advanced-transitions\/<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Transition\u662f\u4ec0\u4e48\uff1f \u5728SwiftUI\u4e2d\uff0ctransition\u51b3\u5b9a\u4e86\u67d0\u4e2aView\u5982\u4f55\u63d2\u5165\u5230\u89c6\u56fe\u6808\u4e2d\uff0c\u6216 [&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\/807"}],"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=807"}],"version-history":[{"count":7,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/807\/revisions"}],"predecessor-version":[{"id":824,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/807\/revisions\/824"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}