<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>macOS 13 - 标签 - 宋明的博客</title><link>https://apolla.cc/tags/macos-13/</link><description>宋明的博客</description><generator>Hugo 0.170.0 &amp; FixIt v1.0.0-rc.5-mwimukpl</generator><language>zh-cn</language><lastBuildDate>Sun, 29 Jan 2023 08:00:00 +0800</lastBuildDate><atom:link href="https://apolla.cc/tags/macos-13/index.xml" rel="self" type="application/rss+xml"/><item><title>5.3 自定义手势</title><link>https://apolla.cc/posts/5.3-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%89%8B%E5%8A%BF/</link><pubDate>Sun, 29 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/5.3-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%89%8B%E5%8A%BF/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt;&lt;/p&gt;&#10;&lt;p&gt;SwiftUI 内置了一些常用手势，它们都实现了 &lt;a href="https://developer.apple.com/documentation/swiftui/gesture" target="_blank" rel="external nofollow noopener noreferrer"&gt;Gesture&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 协议。&lt;/p&gt;&#10;&lt;p&gt;如果需要自定义手势，也需要实现该协议，其声明如下：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;public protocol Gesture {&#10;&#10; /// The type representing the gesture&amp;#39;s value.&#10; associatedtype Value&#10;&#10; /// The type of gesture representing the body of `Self`.&#10; associatedtype Body : Gesture&#10;&#10; /// The content and behavior of the gesture.&#10; var body: Self.Body { get }&#10;}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;和 View 协议类似，body 属性是必须实现的，它的类型由关联类型 Body 定义。另一个关联类型 Value 用于保存手势的状态，在 &lt;code&gt;.onChange&lt;/code&gt; 、 &lt;code&gt;.udpating&lt;/code&gt; 等监听方法中返回该状态。&lt;/p&gt;</description></item><item><title>5.1 常见手势</title><link>https://apolla.cc/posts/5.1-%E5%B8%B8%E8%A7%81%E6%89%8B%E5%8A%BF/</link><pubDate>Sat, 28 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/5.1-%E5%B8%B8%E8%A7%81%E6%89%8B%E5%8A%BF/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h2 class="heading-element" id="tapgesturespatialtapgesture"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/tapgesture" target="_blank" rel="external nofollow noopener noreferrer"&gt;TapGesture&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;、&lt;a href="https://developer.apple.com/documentation/swiftui/spatialtapgesture" target="_blank" rel="external nofollow noopener noreferrer"&gt;SpatialTapGesture&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;&#10; &lt;a href="#tapgesturespatialtapgesture" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h2&gt;&lt;p&gt;要为视图添加点击手势，可以使用 &lt;a href="https://developer.apple.com/documentation/swiftui/view/gesture(_:including:)" target="_blank" rel="external nofollow noopener noreferrer"&gt;gesture(_:including:)&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 绑定一个 TapGesture 实例至视图，也可以直接在视图上使用 &lt;code&gt;.onTapGesture&lt;/code&gt; 方法。&lt;/p&gt;</description></item><item><title>5.2 手势的管理</title><link>https://apolla.cc/posts/5.2-%E6%89%8B%E5%8A%BF%E7%9A%84%E7%AE%A1%E7%90%86/</link><pubDate>Sat, 28 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/5.2-%E6%89%8B%E5%8A%BF%E7%9A%84%E7%AE%A1%E7%90%86/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="手势的状态监听"&gt;&lt;span&gt;手势的状态监听&lt;/span&gt;&#10; &lt;a href="#%e6%89%8b%e5%8a%bf%e7%9a%84%e7%8a%b6%e6%80%81%e7%9b%91%e5%90%ac" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;《常见手势》 演示了通过 &lt;code&gt;.onChanged&lt;/code&gt; 和 &lt;code&gt;.onEnded&lt;/code&gt; 分别监听手势的变化和结束。&lt;/p&gt;</description></item><item><title>4.7 动画的进阶使用</title><link>https://apolla.cc/posts/4.7-%E5%8A%A8%E7%94%BB%E7%9A%84%E8%BF%9B%E9%98%B6%E4%BD%BF%E7%94%A8/</link><pubDate>Tue, 17 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.7-%E5%8A%A8%E7%94%BB%E7%9A%84%E8%BF%9B%E9%98%B6%E4%BD%BF%E7%94%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;h1 class="heading-element" id="transaction"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/transaction" target="_blank" rel="external nofollow noopener noreferrer"&gt;Transaction&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;&#10; &lt;a href="#transaction" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;事务（Transaction）是当前状态更新的上下文，包含状态变化过程中的动画。&lt;/p&gt;</description></item><item><title>4.6 动画原理</title><link>https://apolla.cc/posts/4.6-%E5%8A%A8%E7%94%BB%E5%8E%9F%E7%90%86/</link><pubDate>Fri, 13 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.6-%E5%8A%A8%E7%94%BB%E5%8E%9F%E7%90%86/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;h1 class="heading-element" id="animatable-协议"&gt;&lt;span&gt;Animatable 协议&lt;/span&gt;&#10; &lt;a href="#animatable-%e5%8d%8f%e8%ae%ae" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;我们之所以能看见动画的效果，是因为 SwiftUI 在视图变化的首尾状态之间不断地重绘视图，一系列静态视图因“视觉暂留”作用而造成一种连续的视觉印象，让我们感觉视图动起来了，这其实也是电影的原理。比如一个视图需要从透明度 0 变成 1，SwiftUI 会在 0 和 1 之间不断地作插值运算，不断重绘不同透明度的视图（0，0.1，0.2，0.3 &amp;hellip; 1.0），直到视图不再变化。如果使用 &lt;code&gt;.linear&lt;/code&gt; 指定动画效果，那么视图的重绘过程是匀速的，如果使用 &lt;code&gt;.easeOut&lt;/code&gt;，那么重绘的过程是先快后慢，以此类推。&lt;/p&gt;</description></item><item><title>4.2 图形的绘制</title><link>https://apolla.cc/posts/4.2-%E5%9B%BE%E5%BD%A2%E7%9A%84%E7%BB%98%E5%88%B6/</link><pubDate>Mon, 09 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.2-%E5%9B%BE%E5%BD%A2%E7%9A%84%E7%BB%98%E5%88%B6/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;h1 class="heading-element" id="canvas-的使用"&gt;&lt;span&gt;Canvas 的使用&lt;/span&gt;&#10; &lt;a href="#canvas-%e7%9a%84%e4%bd%bf%e7%94%a8" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;Canvas 字面意思就是“画布”，在这个画布上可以绘制各种图形。与 Shape 不同的是，Canvas 支持即时绘制，比如用户可以使用手指在屏幕上涂鸦。&lt;/p&gt;</description></item><item><title>3.9 自定义布局（Layout）</title><link>https://apolla.cc/posts/3.9-%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B8%83%E5%B1%80layout/</link><pubDate>Sat, 07 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.9-%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B8%83%E5%B1%80layout/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;SwiftUI 内置了丰富的布局容器，也支持简单的布局调整，它们能够解决大多数常用的布局需求。但仍然有所限制，比如 HStack 或者 VStack，它们只能在单一线性轴上进行布局，Grid 虽然可以兼顾横向和纵向，但子视图的位置不能随意调整。&lt;/p&gt;&#10;&lt;p&gt;而 Layout 协议支持自定义布局，我们可以使用它随心所欲地实现各种纷繁的布局效果。&lt;/p&gt;</description></item><item><title>4.1 形状（Shapes）的使用</title><link>https://apolla.cc/posts/4.1-%E5%BD%A2%E7%8A%B6shapes%E7%9A%84%E4%BD%BF%E7%94%A8/</link><pubDate>Sat, 07 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/4.1-%E5%BD%A2%E7%8A%B6shapes%E7%9A%84%E4%BD%BF%E7%94%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="常用的内置形状及样式"&gt;&lt;span&gt;常用的内置形状及样式&lt;/span&gt;&#10; &lt;a href="#%e5%b8%b8%e7%94%a8%e7%9a%84%e5%86%85%e7%bd%ae%e5%bd%a2%e7%8a%b6%e5%8f%8a%e6%a0%b7%e5%bc%8f" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;h2 class="heading-element" id="内置形状"&gt;&lt;span&gt;内置形状&lt;/span&gt;&#10; &lt;a href="#%e5%86%85%e7%bd%ae%e5%bd%a2%e7%8a%b6" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h2&gt;&lt;p&gt;SwiftUI 内置了一些常用的形状，比如矩形、椭圆、正圆等。&lt;/p&gt;</description></item><item><title>3.7 表格（Table）</title><link>https://apolla.cc/posts/3.7-%E8%A1%A8%E6%A0%BCtable/</link><pubDate>Fri, 06 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.7-%E8%A1%A8%E6%A0%BCtable/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;</description></item><item><title>3.11 SwiftUI 布局总结</title><link>https://apolla.cc/posts/3.11-swiftui-%E5%B8%83%E5%B1%80%E6%80%BB%E7%BB%93/</link><pubDate>Thu, 05 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.11-swiftui-%E5%B8%83%E5%B1%80%E6%80%BB%E7%BB%93/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;pre&gt;&lt;code&gt;fileprivate struct ViewTransforming: View {&#10; @State private var aspectRatio: CGFloat = 1.0&#10; &#10; var body: some View {&#10; GroupBox(&amp;#34;aspectRatio&amp;#34;) {&#10; Rectangle()&#10; .fill(.blue.gradient)&#10; .aspectRatio(aspectRatio, contentMode: .fit)&#10; .frame(width: 80)&#10; LabeledContent(&amp;#34;aspectRatio: \(aspectRatio, specifier: &amp;#34;%.1f&amp;#34;)&amp;#34;) {&#10; Slider(value: $aspectRatio, in: 0.5...2.0)&#10; }&#10; }&#10; }&#10;}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/57243677/proportional-height-or-width-in-swiftui" target="_blank" rel="external nofollow noopener noreferrer"&gt;https://stackoverflow.com/questions/57243677/proportional-height-or-width-in-swiftui&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;静态渲染适用于轻量的数据展示，比如 HStack、Grid 等，它们的内容和尺寸都相对固定。SwiftUI 会计算它们包含的所有视图，无论该视图是在屏幕内或屏幕外，如果有少量的视图需要渲染，使用它们是非常合适的。&lt;/p&gt;</description></item><item><title>3.8 共享布局信息</title><link>https://apolla.cc/posts/3.8-%E5%85%B1%E4%BA%AB%E5%B8%83%E5%B1%80%E4%BF%A1%E6%81%AF/</link><pubDate>Thu, 05 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.8-%E5%85%B1%E4%BA%AB%E5%B8%83%E5%B1%80%E4%BF%A1%E6%81%AF/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="geometryreader"&gt;&lt;span&gt;GeometryReader&lt;/span&gt;&#10; &lt;a href="#geometryreader" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/geometryreader" target="_blank" rel="external nofollow noopener noreferrer"&gt;GeometryReader&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 视图的构建闭包内返回了一个 &lt;a href="https://developer.apple.com/documentation/swiftui/geometryproxy" target="_blank" rel="external nofollow noopener noreferrer"&gt;GeometryProxy&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 类型的结构体，通过它可以获取到如下信息：&lt;/p&gt;</description></item><item><title>3.2.1 视图组</title><link>https://apolla.cc/posts/3.2.1-%E8%A7%86%E5%9B%BE%E7%BB%84/</link><pubDate>Wed, 04 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.2.1-%E8%A7%86%E5%9B%BE%E7%BB%84/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="group"&gt;&lt;span&gt;Group&lt;/span&gt;&#10; &lt;a href="#group" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;前面提到过 SwiftUI 能够将各种视图组合在一起，得益于结果生成器，关于结果生成器，参考 《Swift 中的 Result builders》 。&lt;/p&gt;</description></item><item><title>3.4 格子（Grids）</title><link>https://apolla.cc/posts/3.4-%E6%A0%BC%E5%AD%90grids/</link><pubDate>Wed, 04 Jan 2023 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.4-%E6%A0%BC%E5%AD%90grids/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="grid"&gt;&lt;span&gt;Grid&lt;/span&gt;&#10; &lt;a href="#grid" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/grid" target="_blank" rel="external nofollow noopener noreferrer"&gt;Grid&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 和 &lt;a href="https://developer.apple.com/documentation/swiftui/gridrow" target="_blank" rel="external nofollow noopener noreferrer"&gt;GridRow&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 是 iOS 16/macOS 13 新出的功能，用于快速构建静态格子视图。&lt;/p&gt;</description></item><item><title>3.3 布局的调整</title><link>https://apolla.cc/posts/3.3-%E5%B8%83%E5%B1%80%E7%9A%84%E8%B0%83%E6%95%B4/</link><pubDate>Fri, 23 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.3-%E5%B8%83%E5%B1%80%E7%9A%84%E8%B0%83%E6%95%B4/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;调整视图布局的方法是多样的，本文主要介绍通过调整 view 的尺寸、位置以及对齐方式等来实现布局的基础调整，在实际开发中，需要选择合适的方法来实现不同的布局效果。除此以外，后面还会介绍自定义 layout 来实现更加高级和灵活地布局。&lt;/p&gt;&#10;&lt;h1 class="heading-element" id="尺寸"&gt;&lt;span&gt;尺寸&lt;/span&gt;&#10; &lt;a href="#%e5%b0%ba%e5%af%b8" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;h2 class="heading-element" id="padding"&gt;&lt;span&gt;padding&lt;/span&gt;&#10; &lt;a href="#padding" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h2&gt;&lt;p&gt;SwiftUI 提供了多个 padding 方法，可以方便地调整视图各个方向上的内边距，从而影响布局和空间的分配。&lt;/p&gt;</description></item><item><title>3.2 堆叠（Stacks）</title><link>https://apolla.cc/posts/3.2-%E5%A0%86%E5%8F%A0stacks/</link><pubDate>Thu, 22 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.2-%E5%A0%86%E5%8F%A0stacks/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="hstackvstackzstack"&gt;&lt;span&gt;HStack、VStack、ZStack&lt;/span&gt;&#10; &lt;a href="#hstackvstackzstack" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/hstack" target="_blank" rel="external nofollow noopener noreferrer"&gt;HStack&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;、&lt;a href="https://developer.apple.com/documentation/swiftui/vstack" target="_blank" rel="external nofollow noopener noreferrer"&gt;VStack&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;、&lt;a href="https://developer.apple.com/documentation/swiftui/zstack" target="_blank" rel="external nofollow noopener noreferrer"&gt;ZStack&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 分别可以在三个线性轴 x、y、z 方向上组合视图。&lt;/p&gt;</description></item><item><title>3.1 SwiftUI 布局思想简介</title><link>https://apolla.cc/posts/3.1-swiftui-%E5%B8%83%E5%B1%80%E6%80%9D%E6%83%B3%E7%AE%80%E4%BB%8B/</link><pubDate>Wed, 21 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3.1-swiftui-%E5%B8%83%E5%B1%80%E6%80%9D%E6%83%B3%E7%AE%80%E4%BB%8B/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;SwiftUI 的布局过程大致如下：&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;父视图为子视图提供布局空间。&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;若指定了尺寸，父视图提供的布局空间就是指定的尺寸范围。&lt;/li&gt;&#10;&lt;li&gt;若没指定尺寸：&#10;&lt;ul&gt;&#10;&lt;li&gt;若父视图是无边界的，比如 Color 还有下面提到的 ScrollView，它的尺寸默认是无限大（这里的无限大指可以利用的一切空间，下同）。&lt;/li&gt;&#10;&lt;li&gt;若父视图是有边界的，比如 HStack、VStack 等，它的尺寸取决于子视图的尺寸。&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;子视图根据自身内容计算尺寸，并将该信息提供给父视图。&lt;/p&gt;&#10;&lt;p&gt;SwiftUI 中的视图层级类似树状结构，对每个节点视图的 body 属性的计算是个递归的过程，终止条件是遇到 body 属性为 Never 的视图，它们又称为原始视图，是这颗树上的叶子结点。这里提到的父子关系并非绝对概念，子视图可能也作为其它视图的父视图，父子其实是个相对概念。&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;父视图根据子视图提供的尺寸信息计算自身尺寸并对子视图进行布局。&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;若父视图指定了尺寸，则根据指定的尺寸对子视图进行布局。&lt;/li&gt;&#10;&lt;li&gt;若父视图没指定尺寸，则根据子视图提供的尺寸信息计算自身的尺寸并对子视图进行布局。父视图在计算自身尺寸时如果它本身就是无边界的，那么它的尺寸不受子视图的影响。&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ol&gt;</description></item><item><title>2.6 视图生命周期方法</title><link>https://apolla.cc/posts/2.6-%E8%A7%86%E5%9B%BE%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E6%96%B9%E6%B3%95/</link><pubDate>Tue, 20 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.6-%E8%A7%86%E5%9B%BE%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E6%96%B9%E6%B3%95/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="onappear"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/view/onappear(perform:)" target="_blank" rel="external nofollow noopener noreferrer"&gt;onAppear&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;&#10; &lt;a href="#onappear" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;在视图即将出现时会触发 onAppear 方法。&lt;/p&gt;&#10;&lt;p&gt;&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt;&lt;/p&gt;</description></item><item><title>2.7 自定义视图</title><link>https://apolla.cc/posts/2.7-%E8%87%AA%E5%AE%9A%E4%B9%89%E8%A7%86%E5%9B%BE/</link><pubDate>Tue, 20 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.7-%E8%87%AA%E5%AE%9A%E4%B9%89%E8%A7%86%E5%9B%BE/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="自定义-view"&gt;&lt;span&gt;自定义 view&lt;/span&gt;&#10; &lt;a href="#%e8%87%aa%e5%ae%9a%e4%b9%89-view" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;SwiftUI 中的视图都是实现 View 协议的结构体，比如需要自定义一个垂直布局的 Label：&lt;/p&gt;</description></item><item><title>2.4.5 控件-样式</title><link>https://apolla.cc/posts/2.4.5-%E6%8E%A7%E4%BB%B6-%E6%A0%B7%E5%BC%8F/</link><pubDate>Mon, 19 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.4.5-%E6%8E%A7%E4%BB%B6-%E6%A0%B7%E5%BC%8F/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="色调"&gt;&lt;span&gt;色调&lt;/span&gt;&#10; &lt;a href="#%e8%89%b2%e8%b0%83" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;在 《控件-指示器》 一文提到过可以通过 &lt;code&gt;.tint&lt;/code&gt; 方法覆盖程序设置的 accentColor 来给控件指定主色调，但并非所有控件都能生效，比如使用渐变色样式时，无法应用该样式的控件会采用渐变色的第一个颜色进行渲染。&lt;/p&gt;</description></item><item><title>2.5 菜单与命令</title><link>https://apolla.cc/posts/2.5-%E8%8F%9C%E5%8D%95%E4%B8%8E%E5%91%BD%E4%BB%A4/</link><pubDate>Mon, 19 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.5-%E8%8F%9C%E5%8D%95%E4%B8%8E%E5%91%BD%E4%BB%A4/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;Menu 也是一种常用控件，用于创建菜单视图。Button、Toggle、Picker 等常用控件都可以作为 Menu 的子控件，Menu 本身还支持嵌套使用。&lt;/p&gt;&#10;&lt;p&gt;&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt;&lt;/p&gt;&#10;&lt;p&gt;Menu 的构建方法中有一个支持 primaryAction 的闭包，没有添加它时，单击 menu 就会弹出菜单，添加之后，单击 menu 的事件就会成为 primaryAction，长按（iOS）或者点击菜单下拉按钮（macOS）时才会弹出菜单。macOS 的下拉菜单按钮可以通过方法 &lt;a href="https://developer.apple.com/documentation/swiftui/view/menuindicator(_:)" target="_blank" rel="external nofollow noopener noreferrer"&gt;menuIndicator(_:)&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 隐藏。&lt;/p&gt;</description></item><item><title>2.4.4 控件-指示器</title><link>https://apolla.cc/posts/2.4.4-%E6%8E%A7%E4%BB%B6-%E6%8C%87%E7%A4%BA%E5%99%A8/</link><pubDate>Fri, 16 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.4.4-%E6%8E%A7%E4%BB%B6-%E6%8C%87%E7%A4%BA%E5%99%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="progressview"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/progressview" target="_blank" rel="external nofollow noopener noreferrer"&gt;ProgressView&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;&#10; &lt;a href="#progressview" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;ProgressView 有菊花和进度条两种样式，&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt; 。&lt;/p&gt;</description></item><item><title>2.4.1 控件-按钮</title><link>https://apolla.cc/posts/2.4.1-%E6%8E%A7%E4%BB%B6-%E6%8C%89%E9%92%AE/</link><pubDate>Thu, 15 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.4.1-%E6%8E%A7%E4%BB%B6-%E6%8C%89%E9%92%AE/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="按钮样式"&gt;&lt;span&gt;按钮样式&lt;/span&gt;&#10; &lt;a href="#%e6%8c%89%e9%92%ae%e6%a0%b7%e5%bc%8f" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/button" target="_blank" rel="external nofollow noopener noreferrer"&gt;Button&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 可以通过字符串或 view 构建，需要注意的是，通过字符串构建 Button 时， &lt;code&gt;.frame&lt;/code&gt; 是无法扩大点击范围的。因为 frame 的作用是给父视图提供尺寸信息作布局用，我们可以在 frame 的基础上更改 button 的背景，但 button 自身的尺寸依然是由自身内容（字符串）决定的。对于简单的按钮可以直接通过字符串构建，系统也提供了内置的按钮样式。如需更丰富的样式，推荐使用 view 构建，或是自定义按钮样式。&lt;/p&gt;</description></item><item><title>2.4.2 控件-链接</title><link>https://apolla.cc/posts/2.4.2-%E6%8E%A7%E4%BB%B6-%E9%93%BE%E6%8E%A5/</link><pubDate>Thu, 15 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.4.2-%E6%8E%A7%E4%BB%B6-%E9%93%BE%E6%8E%A5/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="link"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/link" target="_blank" rel="external nofollow noopener noreferrer"&gt;Link&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;&#10; &lt;a href="#link" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;Link 可以打开网页链接，如果通用链接（Universal Link）支持，会跳转到对应的 App 页面。&lt;/p&gt;</description></item><item><title>2.4.3 控件-选择器</title><link>https://apolla.cc/posts/2.4.3-%E6%8E%A7%E4%BB%B6-%E9%80%89%E6%8B%A9%E5%99%A8/</link><pubDate>Thu, 15 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.4.3-%E6%8E%A7%E4%BB%B6-%E9%80%89%E6%8B%A9%E5%99%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="toggle"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/toggle" target="_blank" rel="external nofollow noopener noreferrer"&gt;Toggle&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;&#10; &lt;a href="#toggle" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;Toggle 是表示开关状态的控件，默认的颜色风格是绿色，使用 &lt;code&gt;.tint&lt;/code&gt; 可以改变颜色。&lt;/p&gt;</description></item><item><title>2.1.1 文本-Text</title><link>https://apolla.cc/posts/2.1.1-%E6%96%87%E6%9C%AC-text/</link><pubDate>Mon, 05 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.1.1-%E6%96%87%E6%9C%AC-text/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="字符串"&gt;&lt;span&gt;字符串&lt;/span&gt;&#10; &lt;a href="#%e5%ad%97%e7%ac%a6%e4%b8%b2" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;SwiftUI 中涉及到字符串的地方，基本都支持普通的字符串和本地化字符串。&lt;/p&gt;</description></item><item><title>2.1.2 文本-Label</title><link>https://apolla.cc/posts/2.1.2-%E6%96%87%E6%9C%AC-label/</link><pubDate>Mon, 05 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.1.2-%E6%96%87%E6%9C%AC-label/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="构建方法"&gt;&lt;span&gt;构建方法&lt;/span&gt;&#10; &lt;a href="#%e6%9e%84%e5%bb%ba%e6%96%b9%e6%b3%95" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/label" target="_blank" rel="external nofollow noopener noreferrer"&gt;Label&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 可以快速生成图片和文字的组合，默认布局是左图右文。&lt;/p&gt;</description></item><item><title>2.1.3 文本-输入</title><link>https://apolla.cc/posts/2.1.3-%E6%96%87%E6%9C%AC-%E8%BE%93%E5%85%A5/</link><pubDate>Mon, 05 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/2.1.3-%E6%96%87%E6%9C%AC-%E8%BE%93%E5%85%A5/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="textfield"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/textfield" target="_blank" rel="external nofollow noopener noreferrer"&gt;TextField&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;&#10; &lt;a href="#textfield" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;h2 class="heading-element" id="构建及样式"&gt;&lt;span&gt;构建及样式&lt;/span&gt;&#10; &lt;a href="#%e6%9e%84%e5%bb%ba%e5%8f%8a%e6%a0%b7%e5%bc%8f" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h2&gt;&lt;p&gt;TextField 具有多个构建方法，最简单的如下：&lt;/p&gt;</description></item><item><title>1.3.4 工具栏（Toolbars）</title><link>https://apolla.cc/posts/1.3.4-%E5%B7%A5%E5%85%B7%E6%A0%8Ftoolbars/</link><pubDate>Thu, 01 Dec 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3.4-%E5%B7%A5%E5%85%B7%E6%A0%8Ftoolbars/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;SwiftUI 将 navigationBar、bottomBar、tabBar、windowToolbar 等视图的功能和样式都整合在了工具栏中，使用时调用的 api 都是以 .toolbar 开头的。&lt;/p&gt;&#10;&lt;p&gt;比如要给导航栏右侧添加一个分享按钮：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;#if os(iOS)&#10;NavigationStack {&#10; ContentView()&#10; .toolbar {&#10; ToolbarItem(placement: .navigationBarTrailing) {&#10; Button {&#10; } label: {&#10; Image(systemName: &amp;#34;square.and.arrow.up&amp;#34;)&#10; }&#10; }&#10; }&#10;}&#10;#endif&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;span style="background: #007BFF; color: white; padding: 3px 10px; border-radius: 5px"&gt;&amp;gt; 查看示例&lt;/span&gt;&lt;/p&gt;</description></item><item><title>1.3.0 TabView 的使用</title><link>https://apolla.cc/posts/1.3.0-tabview-%E7%9A%84%E4%BD%BF%E7%94%A8/</link><pubDate>Wed, 23 Nov 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3.0-tabview-%E7%9A%84%E4%BD%BF%E7%94%A8/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="基础使用"&gt;&lt;span&gt;基础使用&lt;/span&gt;&#10; &lt;a href="#%e5%9f%ba%e7%a1%80%e4%bd%bf%e7%94%a8" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/tabview" target="_blank" rel="external nofollow noopener noreferrer"&gt;TabView&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 等同于 UIKit 中的 UITabBar，先来看看它的基础使用：&lt;/p&gt;</description></item><item><title>1.3.2 导航之 NavigationSplitView</title><link>https://apolla.cc/posts/1.3.2-%E5%AF%BC%E8%88%AA%E4%B9%8B-navigationsplitview/</link><pubDate>Mon, 21 Nov 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3.2-%E5%AF%BC%E8%88%AA%E4%B9%8B-navigationsplitview/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/navigationsplitview" target="_blank" rel="external nofollow noopener noreferrer"&gt;NavigationSplitView&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 用于快速构建多栏视图，它支持在 Apple 全平台上使用。根据设备屏幕尺寸（Size Class）的差异，NavigationSplitView 的样式有所不同。&lt;/p&gt;&#10;&lt;p&gt;Size Class 分为 regular 和 compact，NavigationSplitView 相应的表现分别是分栏和导航栈。正如示例所示，在 iPhone 14 Plus 或 iPhone 14 Pro Max 机型上，竖屏时 Size Class 是 compact，导航行为就是常见的 push 和 pop。而横屏时，Size Class 是 regular，视图会变成分栏样式。&lt;/p&gt;</description></item><item><title>1.3.1 导航之 NavigationStack</title><link>https://apolla.cc/posts/1.3.1-%E5%AF%BC%E8%88%AA%E4%B9%8B-navigationstack/</link><pubDate>Mon, 05 Sep 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3.1-%E5%AF%BC%E8%88%AA%E4%B9%8B-navigationstack/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;iOS 16 废弃了 NavigationView，使用更加灵活的 &lt;a href="https://developer.apple.com/documentation/swiftui/navigationstack" target="_blank" rel="external nofollow noopener noreferrer"&gt;NavigationStack&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;、&lt;a href="https://developer.apple.com/documentation/swiftui/navigationsplitview" target="_blank" rel="external nofollow noopener noreferrer"&gt;NavigationSplitView&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 管理导航栈。二者在 iOS、iPadOS、macOS 上均可使用，但在不同平台表现不一。后文主要演示 NavigationStack 在 iPhone、iPad 上的使用，NavigationSplitView 在 iPad、Mac 上的使用。&lt;/p&gt;</description></item><item><title>1.3 SwiftUI 中的场景</title><link>https://apolla.cc/posts/1.3-swiftui-%E4%B8%AD%E7%9A%84%E5%9C%BA%E6%99%AF/</link><pubDate>Mon, 29 Aug 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.3-swiftui-%E4%B8%AD%E7%9A%84%E5%9C%BA%E6%99%AF/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;p&gt;&lt;em&gt;鉴于 Scene 比较特殊，难以在 Eul 中内置示例，笔者为其单独创建了一个样例工程，源码：&lt;a href="https://github.com/zzzwco/resources/tree/main/eul/SampleScene" target="_blank" rel="external nofollow noopener noreferrer"&gt;Eul/SampleScene&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;。&lt;/em&gt;&lt;/p&gt;&#10;&lt;p&gt;在 [[1.1.2 生命周期的演变]]中已经介绍过一些关于场景的概念了，下面逐一介绍 SwiftUI 内置的场景及其用法。&lt;/p&gt;&#10;&lt;h2 class="heading-element" id="windowgroup"&gt;&lt;span&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/windowgroup?changes=latest_minor" target="_blank" rel="external nofollow noopener noreferrer"&gt;WindowGroup&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;&#10; &lt;a href="#windowgroup" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h2&gt;&lt;p&gt;这是最重要、最常用的场景，新建一个 SwiftUI 工程时，在 app 入口处就会看到如下代码：&lt;/p&gt;</description></item><item><title>1.2 生命周期的演变</title><link>https://apolla.cc/posts/1.2-%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%9A%84%E6%BC%94%E5%8F%98/</link><pubDate>Sat, 20 Aug 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.2-%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%9A%84%E6%BC%94%E5%8F%98/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;iOS 13 之前，app 的入口以及生命周期方法由 &lt;a href="https://developer.apple.com/documentation/uikit/uiapplicationdelegate" target="_blank" rel="external nofollow noopener noreferrer"&gt;UIApplicationDelegate&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 协议定义，通常我们使用 &lt;a href="https://developer.apple.com/documentation/uikit/uiwindow" target="_blank" rel="external nofollow noopener noreferrer"&gt;UIWindow&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 实例作为呈现界面和分发事件的窗口。&lt;/p&gt;&#10;&lt;p&gt;iOS 13 开始，iPad 支持多窗口模式。 臃肿的 AppDelegate 不堪重负，于是它将各个窗口的管理工作分配给 &lt;a href="https://developer.apple.com/documentation/uikit/uiscenedelegate" target="_blank" rel="external nofollow noopener noreferrer"&gt;UISceneDelegate&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 实例。&lt;/p&gt;&#10;&lt;p&gt;iOS 14 新增了 SwiftUI 专属的 &lt;a href="https://developer.apple.com/documentation/swiftui/app" target="_blank" rel="external nofollow noopener noreferrer"&gt;App&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 协议，它定义了 app 的结构和行为。创建一个 SwiftUI 项目时，Xcode 默认实现了一个 App 实例：&lt;/p&gt;</description></item><item><title>1.1 App 入口与配置</title><link>https://apolla.cc/posts/1.1-app-%E5%85%A5%E5%8F%A3%E4%B8%8E%E9%85%8D%E7%BD%AE/</link><pubDate>Mon, 15 Aug 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.1-app-%E5%85%A5%E5%8F%A3%E4%B8%8E%E9%85%8D%E7%BD%AE/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="入口"&gt;&lt;span&gt;入口&lt;/span&gt;&#10; &lt;a href="#%e5%85%a5%e5%8f%a3" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;当我们 &lt;a href="https://developer.apple.com/documentation/xcode/creating-an-xcode-project-for-an-app" target="_blank" rel="external nofollow noopener noreferrer"&gt;创建一个工程&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 后，首先看到的就是如下代码：&lt;/p&gt;</description></item><item><title>1.1 App 入口与配置_副本</title><link>https://apolla.cc/posts/1.1-app-%E5%85%A5%E5%8F%A3%E4%B8%8E%E9%85%8D%E7%BD%AE_%E5%89%AF%E6%9C%AC/</link><pubDate>Mon, 15 Aug 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/1.1-app-%E5%85%A5%E5%8F%A3%E4%B8%8E%E9%85%8D%E7%BD%AE_%E5%89%AF%E6%9C%AC/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;h1 class="heading-element" id="入口"&gt;&lt;span&gt;入口&lt;/span&gt;&#10; &lt;a href="#%e5%85%a5%e5%8f%a3" class="heading-mark"&gt;&lt;svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"&gt;&lt;path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&#10;&lt;/h1&gt;&lt;p&gt;当我们 &lt;a href="https://developer.apple.com/documentation/xcode/creating-an-xcode-project-for-an-app" target="_blank" rel="external nofollow noopener noreferrer"&gt;创建一个工程&lt;i class="fa-solid fa-external-link-alt fa-xs ms-1 text-secondary" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; 后，首先看到的就是如下代码：&lt;/p&gt;</description></item><item><title>3 Swift 中的 Result builders</title><link>https://apolla.cc/posts/3-swift-%E4%B8%AD%E7%9A%84-result-builders/</link><pubDate>Tue, 30 Aug 2022 08:00:00 +0800</pubDate><guid>https://apolla.cc/posts/3-swift-%E4%B8%AD%E7%9A%84-result-builders/</guid><category domain="https://apolla.cc/categories/swiftui/">SwiftUI</category><description>&lt;br&gt;&#10;&lt;br&gt;&#10;&lt;p&gt;在以往的命令式编程中，通常这样构建视图：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;let label = UILabel()&#10;label.frame = self.view.bounds&#10;self.view.addSubview(label)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;但 SwiftUI 采用的是声明式语法：&lt;/p&gt;&#10;&lt;pre&gt;&lt;code&gt;VStack {&#10; Text(&amp;#34;1&amp;#34;)&#10;&#9;List {&#10; Text(&amp;#34;&amp;#34;)&#10; }&#10;}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;显而易见，SwiftUI 比 UIKit 要简洁地多，我们可以轻松地将不同的视图组合成复杂的界面。这得益于 Result builders（结果构造器），它使 SwiftUI 成为了特定领域语言（DSL）。&lt;/p&gt;</description></item></channel></rss>