Communitygithub.com

ComeOnOliver/skillshub

在實作 iOS 26 SwiftUI 功能時使用,涵蓋 Liquid Glass 設計系統、效能改進、@Animatable 巨集、3D 空間佈局、場景橋接、WebView/WebPage、AttributedString 富文本編輯、拖放增強以及 visionOS 整合。

skillshub 是什麼?

此技能提供適用於 iOS 26 及相關 Apple 平台(iPadOS 26、macOS Tahoe、watchOS 26、visionOS 26)的全面 SwiftUI 新功能指南,重點介紹 Liquid Glass 設計系統,並涵蓋效能改進、新的 @Animatable 巨集、3D 空間佈局、場景橋接、WebView/WebPage 嵌入、AttributedString 富文本編輯、多項目拖放增強,以及 visionOS 整合。它詳細說明了新 API(例如 ToolbarItemGroup、Slider 自訂刻度標記、safeAreaBar 視圖修飾符)以及可提升開發者生產力的進階功能。該技能旨在幫助開發者採用最新 SwiftUI 功能,支援從視覺設計、使用者互動到跨裝置多工的所有需求,並確保最佳效能。它整合了多個 Apple 生態系統的更新,使開發者能夠建立更具沉浸感、反應更迅速、視覺更統一的應用程式。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/CharlesWiltgen/Axiom/axiom-swiftui-26-ref

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

SwiftUI 26 功能

概述

iOS 26、iPadOS 26、macOS Tahoe、watchOS 26 和 visionOS 26 中 SwiftUI 新功能的完整指南。從 Liquid Glass 設計系統到富文本編輯,這些增強功能使 SwiftUI 在 Apple 所有平台上更強大。

核心原則 從底層效能改進一直到使用者介面中的按鈕,整個系統都有一些重大提升。

何時使用此技能

  • 採用 Liquid Glass 設計系統
  • 使用 AttributedString 實作富文本編輯
  • 使用 WebView 嵌入網頁內容
  • 最佳化列表和滾動效能
  • 使用 @Animatable 巨集製作自訂動畫
  • 在 visionOS 上建置 3D 空間佈局
  • 將 SwiftUI 場景橋接到 UIKit/AppKit 應用程式
  • 實作多項目拖放
  • 使用 Chart3D 建立 3D 圖表
  • 為 visionOS 或 CarPlay 新增小工具
  • 為滑桿新增自訂刻度標記(章節標記、數值指示器)
  • 使用 enabledBounds 限制滑桿選擇範圍
  • 自訂滑桿外觀(拇指旋鈕可見度、目前數值標籤)
  • 建立帶有模糊效果的黏性安全區域列
  • 在應用程式內瀏覽器中開啟 URL
  • 使用系統樣式的關閉和確認按鈕
  • 套用玻璃按鈕樣式(iOS 26.1+)
  • 控制按鈕大小行為
  • 實作精簡搜尋工具列
  • 調整文字行高或基線間距

系統需求

iOS 26+、iPadOS 26+、macOS Tahoe+、watchOS 26+、visionOS 26+


Liquid Glass 設計系統

完整說明,請參閱 axiom-liquid-glass(設計原則、變體、審查壓力)和 axiom-liquid-glass-ref(應用範圍採用指南)。本節僅涵蓋 WWDC 256 特定 API。

自動採用

使用 iOS 26 SDK 重新編譯 — 導覽容器、標籤列、工具列、切換開關、分段選擇器和滑桿會自動採用新設計。邊框按鈕預設為膠囊形狀。表格視圖會取得 Liquid Glass 背景(移除任何自訂的 presentationBackground)。

工具列 API(iOS 26)

ToolbarSpacer

.toolbar {
    ToolbarItem(placement: .bottomBar) { Button("Archive", systemImage: "archivebox") { } }
    ToolbarSpacer(.flexible, placement: .bottomBar)  // Push items apart
    ToolbarItem(placement: .bottomBar) { Button("Compose", systemImage: "square.and.pencil") { } }
}
// .fixed 在視覺上分隔群組;.flexible 則會推開(類似 HStack 中的 Spacer)

ToolbarItemGroup(視覺分組)

ToolbarItemGroup 中的項目共用一個玻璃背景「藥丸」。ToolbarItemPlacement 控制視覺外觀:confirmationAction → glassProminent 樣式,cancellationAction → 標準玻璃。使用 .sharedBackgroundVisibility(.hidden) 將項目(例如頭像)排除在群組背景之外。

工具列變形

將 .toolbar {} 附加到 NavigationStack 內部的個別視圖(而非 NavigationStack 本身)。iOS 26 在推入/彈出期間會在每個視圖的工具列之間變形。使用 toolbar(id:) 搭配跨畫面一致的 ToolbarItem(id:),使項目保持穩定(無彈跳):

// MailboxList
.toolbar(id: "main") {
    ToolbarItem(id: "filter", placement: .bottomBar) { Button("Filter") { } }
    ToolbarSpacer(.flexible, placement: .bottomBar)
    ToolbarItem(id: "compose", placement: .bottomBar) { Button("New Message") { } }
}
// MessageList — "filter" 不存在(動畫消失),"compose" 保持穩定
.toolbar(id: "main") {
    ToolbarSpacer(.flexible, placement: .bottomBar)
    ToolbarItem(id: "compose", placement: .bottomBar) { Button("New Message") { } }
}

#1 陷阱:將工具列放在 NavigationStack 上 = 沒有東西可以變形。

DefaultToolbarItem

在工具列佈局中重新定位系統提供的項目(例如搜尋):

DefaultToolbarItem(kind: .search, placement: .bottomBar)
// 取代符合類型的系統預設位置

在收合的 NavigationSplitView 側邊欄中使用,以指定在 iPhone 上哪個欄位顯示搜尋。為了向後相容,請包裹在 if #available(iOS 26.0, *) 中。

使用者可自訂的工具列

toolbar(id:) 啟用使用者自訂(重新排列、顯示/隱藏)。在 iPadOS 上僅 .secondaryAction 項目支援自訂。對可選項目使用 showsByDefault: false。為 macOS 選單項目新增 ToolbarCommands()。

其他工具列功能

  • .navigationSubtitle("3 unread") — 標題下方的次要行
  • .badge(3) 套用於工具列項目 — 通知計數
  • 單色圖示渲染 — 減少視覺雜訊;為意義而著色,而非裝飾
  • 滾動邊緣模糊 — 自動,無需程式碼

底部對齊搜尋

基礎搜尋 API:請參閱 axiom-swiftui-search-ref。本節僅涵蓋 iOS 26 的改進。

NavigationSplitView {
    List { }.searchable(text: $searchText)
}
// 在 iPhone 上底部對齊,在 iPad 上為頂部尾端(自動)
// 使用 placement: .sidebar 在 iPad 上恢復側邊欄嵌入的搜尋
  • searchToolbarBehavior(.minimize) — 點按時展開的精簡搜尋
  • Tab(role: .search) — 專用搜尋標籤頁;搜尋欄位取代標籤列。請參閱 swiftui-nav-ref 第 5.7 節

自訂視圖的玻璃效果

Button("To Top", systemImage: "chevron.up") { scrollToTop() }
    .padding()
    .glassEffect()  // 對 iOS 上的自訂控制項新增 .interactive
  • GlassEffectContainer — 當附近有多個玻璃元素時需要(玻璃無法對玻璃取樣)
  • glassEffectID(_:in:) — 使用命名空間在玻璃元素之間進行流暢的變形轉換
  • 表格變形 — 使用 .matchedTransitionSource + .navigationTransition(.zoom(...)) 從按鈕變形為表格

按鈕與控制項變更

  • 邊框按鈕預設為膠囊形狀(使用 .buttonBorderShape(.roundedRectangle) 覆蓋)
  • .controlSize(.extraLarge) — 新的特大按鈕大小
  • 容器上的 .controlSize(.small) — 保留 iOS 26 之前的密度
  • GlassButtonStyle(.clear/.glass/.tint) — 玻璃按鈕變體(iOS 26.1+)
  • .buttonSizing(.fit/.stretch/.flexible) — 控制按鈕佈局行為
  • Button(role: .close) / Button(role: .confirm) — 系統樣式的關閉/確認
  • .clipShape(.rect(cornerRadius: 12, style: .containerConcentric)) — 角落同心性
  • 選單:圖示位於前緣,iOS/macOS 一致

滑桿增強功能

iOS 26 新增自訂刻度標記、受限選擇範圍、目前數值標籤以及拇指旋鈕可見度控制。

滑桿刻度

核心類型:SliderTick<V>、SliderTickContentForEach、SliderTickBuilder

// 帶有標籤的靜態刻度
Slider(value: $value, in: 0...10) {
    Text("Rating")
} ticks: {
    SliderTick(0) { Text("Min") }
    SliderTick(5) { Text("Mid") }
    SliderTick(10) { Text("Max") }
}

// 來自集合的動態刻度
SliderTickContentForEach(stops, id: \.self) { value in
    SliderTick(value) { Text("\(Int(value))°").font(.caption2) }
}

// 基於步進的刻度(為每個步進值呼叫)
Slider(value: $volume, in: 0...10, step: 2, label: { Text("Volume") }, tick: { value in
    SliderTick(value) { Text("\(Int(value))") }
})

API 限制:SliderTickContentForEach 要求 Data.Element 符合 SliderTick<V> 值類型。對於自訂結構,提取數值:chapters.map(\.time) 然後透過 chapters.first(where: { $0.time == time }) 查詢標籤。

功能完整的滑桿

Slider(
    value: $rating, in: 0...100,
    neutralValue: 50,           // 起始點 / 中心值
    enabledBounds: 20...80,     // 限制可選擇範圍
    label: { Text("Rating") },
    currentValueLabel: { Text("\(Int(rating))") },
    minimumValueLabel: { Text("0") },
    maximumValueLabel: { Text("100") },
    ticks: { SliderTick(50) { Text("Mid") } },
    onEditingChanged: { editing in print(editing ? "Started" : "Ended") }
)

sliderThumbVisibility

.sliderThumbVisibility(.hidden) — 隱藏媒體進度指示器和極簡 UI 的拇指旋鈕。選項:.automatic、.visible、.hidden。在 watchOS 上始終可見。


新的視圖修飾符

safeAreaBar

具有整合漸進式模糊效果的黏性列:

List { ForEach(1...20, id: \.self) { Text("\($0). Item") } }
    .safeAreaBar(edge: .bottom) {
        Text("Bottom Action Bar").padding(.vertical, 15)
    }
    .scrollEdgeEffectStyle(.soft, for: .bottom) // 或 .hard

運作方式類似於 safeAreaInset,但帶有模糊效果。列保持固定,而內容在其下方滾動。

onOpenURL 增強功能

@Environment(\.openURL) var openURL
// openURL(url, prefersInApp: true) — 在類似 SFSafariViewController 的應用程式內瀏覽器中開啟
// 預設的 Link 會在 Safari 中開啟;prefersInApp 讓使用者留在您的應用程式內

searchToolbarBehavior

請參閱 axiom-swiftui-search-ref 以了解基礎 .searchable API。iOS 26 新增:

.searchable(text: $searchText)
.searchToolbarBehavior(.minimize)  // 精簡按鈕,點按時展開

另外:.searchPresentationToolbarBehavior(.avoidHidingContent)(iOS 17.1+)在搜尋期間保持標題可見。

向後相容包裝器,適用於以 iOS 18+26 為目標的應用程式:

extension View {
    @ViewBuilder func minimizedSearch() -> some View {
        if #available(iOS 26.0, *) {
            self.searchToolbarBehavior(.minimize)
        } else { self }
    }
}

// 用法
.searchable(text: $searchText)
.minimizedSearch()

工具列項目的可用性模式:

.toolbar {
    if #available(iOS 26.0, *) {
        DefaultToolbarItem(kind: .search, placement: .bottomBar)
        ToolbarSpacer(.flexible, placement: .bottomBar)
    }
    ToolbarItem(placement: .bottomBar) {
        NewNoteButton()
    }
}
.searchable(text: $searchText)

按鈕角色、GlassButtonStyle、buttonSizing — 請參閱上方 Liquid Glass 設計系統章節。

lineHeight(iOS 26)

設定文字行之間的基線到基線距離。比 .lineSpacing() 更直觀,後者測量的是行底部到下一行頂部的距離。

預設值

Text("Lorem ipsum...")
    .lineHeight(.loose)     // 為開放佈局增加間距
    .lineHeight(.tight)     // 為緊湊佈局減少間距
    .lineHeight(.normal)    // 基於字體大小倍數的固定高度
    .lineHeight(.variable)  // 使用字體度量進行高度計算

精確控制

// 按字體大小比例縮放
Text("Scales with text size")
    .lineHeight(.multiple(factor: 2))

// 相對於字號,帶固定增量
Text("Point-size relative")
    .lineHeight(.leading(increase: 30))

// 絕對固定值 — 不隨 Dynamic Type 縮放
Text("Fixed height")
    .lineHeight(.exact(points: 30))

AttributedString 支援

var s = AttributedString("Paragraph\nwith multiple\nlines.")
s.lineHeight = .exact(points: 32)
s.lineHeight = .multiple(factor: 2.5)
s.lineHeight = .loose

與現有 API 的比較

API測量方式可用性
.lineHeight()基線到基線iOS 26+
.lineSpacing()行底部到下一行頂部iOS 13+
.font(.body.leading(.tight))字體層級的 leading 預設值iOS 14+

交叉參考 axiom-typography-ref — 完整的排版系統,包括 Dynamic Type、追蹤和國際化


iPad 增強功能

選單列

透過向下滑動選單存取常見動作

.commands {
    TextEditingCommands() // 與 macOS 選單列相同的 API

    CommandGroup(after: .newItem) {
        Button("Add Note") {
            addNote()
        }
        .keyboardShortcut("n", modifiers: [.command, .shift])
    }
}
// 當使用者向下滑動時,在 iPad 上建立選單列

可調整大小的視窗

在 iPad 上流暢調整大小

// 需要遷移:
// 在 iPadOS 26 中移除已棄用的屬性列表鍵:
// UIRequiresFullscreen(整個鍵已棄用,所有值)

// 對於分割視圖導覽,系統會根據調整大小期間的可用空間自動顯示/隱藏欄位
NavigationSplitView {
    Sidebar()
} detail: {
    Detail()
}
// 自動適應調整大小

參考文獻 "Elevate the design of your iPad app"(WWDC 2025)


macOS 視窗增強功能

同步視窗調整大小動畫

.windowResizeAnchor(.topLeading) // 自訂動畫起始位置

// SwiftUI 現在會同步內容視圖大小變更和視窗調整大小之間的動畫
// 非常適合在切換標籤頁時保持連續性

效能改進

List 效能(以 macOS 為重點)

大型列表的巨大效能提升

  • macOS 上超過 100,000 個項目的列表載入速度快 6 倍
  • 大型列表的更新速度快 16 倍
  • 列表越大,效能提升越顯著
  • 改進適用於所有平台(iOS、iPadOS、watchOS)
List(trips) { trip in // 10萬+ 個項目
    TripRow(trip: trip)
}
// 在 macOS 上載入速度快 6 倍,更新速度快 16 倍(iOS 26+)

滾動效能

減少掉幀

SwiftUI 改善了 iOS 和 macOS 上使用者介面更新的排程。這提高了回應速度,並讓 SwiftUI 可以做更多工作來準備即將到來的影格。總而言之,它減少了您的應用程式在以高影格率快速滾動時掉幀的可能性。

帶有 Lazy Stacks 的嵌套 ScrollViews

照片輪播和多軸滾動

ScrollView(.horizontal) {
    LazyHStack {
        ForEach(photoSets) { photoSet in
            ScrollView(.vertical) {
                LazyVStack {
                    ForEach(photoSet.photos) { photo in
                        PhotoView(photo: photo)
                    }
                }
            }
        }
    }
}
// 嵌套的 ScrollView 現在可以使用 lazy stacks 正確延遲載入
// 非常適合建置照片輪播

SwiftUI 效能檢測工具

Xcode 中的新效能分析工具

可用的通道:

  • 長視圖主體更新 — 識別昂貴的主體計算
  • 平台視圖更新 — 追蹤

…

[截斷以進行翻譯]

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相關技能