关于 ios-liquid-glass
面向 iOS 26 及更高版本 Apple Liquid Glass 设计系统的 API 参考 Skill,帮助开发者实现玻璃效果和导航样式,并了解系统的无障碍适配行为。
主要功能
- 01说明玻璃效果及其变体
- 02涵盖 GlassEffectContainer 与形变
- 03展示导航界面模式
- 04介绍无障碍适配行为
- 05提供 SF Symbols 与触觉示例
适用场景
- 01在 SwiftUI 中实现玻璃材质
- 02构建玻璃风格的标签栏、工具栏或弹层
- 03检查玻璃效果对无障碍设置的响应
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ prisma-labs-dev/ apple-skills --skill ios-liquid-glass安装后在 Claude Code 中输入/ios-liquid-glass确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
adopting-liquid-glass.mdadopting-liquid-glass.videos.mdapplying-to-custom-views.mdapplying-to-custom-views.videos.mdglass.mdglasseffect.mdglasseffectcontainer.mdlandmarks-activity-badges.mdlandmarks-background-extension.mdlandmarks-building-app.mdlandmarks-horizontal-scrolling.mdlandmarks-toolbar-glass.mdliquid-glass-overview.mdreference.mdview-glasseffect.mdview-glasseffectid.mdview-scrolledgeeffectstyle.md详细介绍
iOS Liquid Glass 参考
Liquid Glass 设计系统(iOS 26+)的 API 参考:玻璃效果、容器、形变过渡及相关系统行为。本文档介绍系统提供的功能,设计方向由你决定。
适用场景
- 实现玻璃材质、
glassEffect修饰符或GlassEffectContainer - 使用系统玻璃效果的导航界面(标签栏、工具栏、工作表)
- 检查玻璃效果如何适配辅助功能设置
- 使用 Icon Composer 创建 App 图标
Apple 声明的设计原则
Apple 用三项原则描述 Liquid Glass(供参考,并非强制要求):
| 原则 | 描述 |
|---|---|
| 层级 | 控件悬浮于内容之上。玻璃用于框定内容,而非遮挡内容。 |
| 和谐 | 软件设计与硬件相协调,包括同心圆角和流畅手势。 |
| 一致性 | 适配 iPhone、iPad 和 Mac——保持相同特征,并根据情境呈现。 |
有一项值得了解的功能限制:玻璃效果是为导航和控件层设计的。将其应用于内容界面会破坏其采样模型(见下文的容器)。
Liquid Glass 核心 API
基本玻璃效果
import SwiftUI
// Simple glass application
Text("Action")
.padding()
.glassEffect() // .regular variant, .capsule shape
// With explicit parameters
Button("Confirm") { }
.padding()
.glassEffect(.regular, in: RoundedRectangle(cornerRadius: 12), isEnabled: true)
玻璃变体
| 变体 | 用例 |
|---|---|
.regular | 工具栏、导航栏、标签栏、标准控件 |
.clear | 媒体(照片、地图、视频)上方的悬浮控件 |
.identity | 条件禁用:glassEffect(isActive ? .regular : .identity) |
玻璃修饰符
// Semantic tinting
.glassEffect(.regular.tint(.accentColor))
// Interactive behaviors (scaling, shimmer, touch illumination)
.glassEffect(.regular.interactive())
// Combined
.glassEffect(.regular.tint(.blue).interactive())
自定义形状
// Standard shapes
.glassEffect(.regular, in: .capsule)
.glassEffect(.regular, in: .circle)
.glassEffect(.regular, in: RoundedRectangle(cornerRadius: 16))
// Container-concentric (matches device/container corners)
.glassEffect(.regular, in: .rect(cornerRadius: .containerConcentric))
GlassEffectContainer 与形变
容器设置
玻璃无法采样其他玻璃。包含多个玻璃元素时请使用容器:
GlassEffectContainer(spacing: 30) {
HStack(spacing: 20) {
ForEach(actions) { action in
Button(action.title, systemImage: action.icon) { }
.frame(width: 44, height: 44)
.glassEffect(.regular.interactive())
}
}
}
形变过渡
struct ExpandableActions: View {
@State private var isExpanded = false
@Namespace private var namespace
var body: some View {
GlassEffectContainer(spacing: 30) {
VStack(spacing: 30) {
if isExpanded {
ActionButton(icon: "rotate.right")
.glassEffectID("rotate", in: namespace)
}
HStack(spacing: 30) {
if isExpanded {
ActionButton(icon: "slider.horizontal.3")
.glassEffectID("adjust", in: namespace)
}
Button {
withAnimation(.bouncy) { isExpanded.toggle() }
} label: {
Image(systemName: isExpanded ? "xmark" : "plus")
.frame(width: 56, height: 56)
}
.glassEffect(.regular.tint(.accentColor).interactive())
.glassEffectID("toggle", in: namespace)
if isExpanded {
ActionButton(icon: "crop")
.glassEffectID("crop", in: namespace)
}
}
if isExpanded {
ActionButton(icon: "wand.and.stars")
.glassEffectID("enhance", in: namespace)
}
}
}
}
}
导航模式
标签栏(悬浮)
TabView {
Tab("Home", systemImage: "house") {
HomeView()
}
Tab("Search", systemImage: "magnifyingglass") {
SearchView()
}
Tab("Profile", systemImage: "person") {
ProfileView()
}
}
// Tab bar now floats, reacts to background, collapses on scroll
带分组的工具栏
.toolbar {
ToolbarItemGroup(placement: .topBarTrailing) {
Button("Edit", systemImage: "pencil") { }
Button("Share", systemImage: "square.and.arrow.up") { }
}
ToolbarSpacer(.flexible, placement: .topBarTrailing)
ToolbarItem(placement: .topBarTrailing) {
Button("Done", systemImage: "checkmark") { }
.tint(.accentColor)
}
}
带形变效果的工作表
struct ContentView: View {
@State private var showSettings = false
@Namespace private var namespace
var body: some View {
NavigationStack {
ContentView()
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("Settings", systemImage: "gear") {
showSettings = true
}
.matchedTransitionSource(id: "settings", in: namespace)
}
}
.sheet(isPresented: $showSettings) {
SettingsView()
.navigationTransition(.zoom(sourceID: "settings", in: namespace))
.presentationDetents([.medium, .large])
}
}
}
}
SF Symbols 效果
Image(systemName: "checkmark.circle")
.symbolEffect(.drawOn, value: isComplete)
Image(systemName: "heart.fill")
.symbolEffect(.bounce, value: isFavorite)
触觉 API
import UIKit
// Impact feedback
let generator = UIImpactFeedbackGenerator(style: .medium)
generator.impactOccurred()
// Selection feedback
let selection = UISelectionFeedbackGenerator()
selection.selectionChanged()
// Success/error
let notification = UINotificationFeedbackGenerator()
notification.notificationOccurred(.success)
辅助功能行为
自动玻璃适配
玻璃会自动适配以下设置:
- 降低透明度:增加磨砂效果
- 增强对比度:边框更醒目
- 减少动态效果:减弱动画
手动检查
@Environment(\.accessibilityReduceTransparency) var reduceTransparency
@Environment(\.accessibilityReduceMotion) var reduceMotion
var animation: Animation? {
reduceMotion ? nil : .bouncy
}
系统要求:触控目标至少为 44x44pt,提供辅助功能标签,并支持动态字体。
参考资料
Apple 官方文档链接、WWDC 会话 ID 和 API 快速参考表,请参阅 reference.md。
评论
支持 Markdown