swiftui-liquid-glass
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSwiftUI Liquid Glass
SwiftUI Liquid Glass
Overview
概述
Use this skill to build or review SwiftUI features that fully align with the iOS 26+ Liquid Glass API. Prioritize native APIs (, , glass button styles) and Apple design guidance. Keep usage consistent, interactive where needed, and performance aware.
glassEffectGlassEffectContainer使用本技能构建或评审完全符合iOS 26+ Liquid Glass API的SwiftUI功能。优先使用原生API(、、玻璃按钮样式)并遵循Apple设计指南。确保使用方式一致、必要时具备交互性,同时兼顾性能。
glassEffectGlassEffectContainerWorkflow Decision Tree
工作流决策树
Choose the path that matches the request:
选择与请求匹配的路径:
1) Review an existing feature
1) 评审现有功能
- Inspect where Liquid Glass should be used and where it should not.
- Verify correct modifier order, shape usage, and container placement.
- Check for iOS 26+ availability handling and sensible fallbacks.
- 检查应使用和不应使用Liquid Glass的场景。
- 验证修饰符顺序、形状使用和容器放置是否正确。
- 检查iOS 26+兼容性处理是否到位,以及是否有合理的降级方案。
2) Improve a feature using Liquid Glass
2) 使用Liquid Glass改进现有功能
- Identify target components for glass treatment (surfaces, chips, buttons, cards).
- Refactor to use where multiple glass elements appear.
GlassEffectContainer - Introduce interactive glass only for tappable or focusable elements.
- 确定需要应用玻璃效果的目标组件(表面、芯片、按钮、卡片)。
- 当存在多个玻璃元素时,重构为使用。
GlassEffectContainer - 仅为可点击或可聚焦的元素添加交互式玻璃效果。
3) Implement a new feature using Liquid Glass
3) 使用Liquid Glass实现新功能
- Design the glass surfaces and interactions first (shape, prominence, grouping).
- Add glass modifiers after layout/appearance modifiers.
- Add morphing transitions only when the view hierarchy changes with animation.
- 首先设计玻璃表面和交互逻辑(形状、突出度、分组)。
- 在布局/外观修饰符之后添加玻璃修饰符。
- 仅当视图层级随动画变化时,添加形态转换效果。
Core Guidelines
核心指南
- Prefer native Liquid Glass APIs over custom blurs.
- Use when multiple glass elements coexist.
GlassEffectContainer - Apply after layout and visual modifiers.
.glassEffect(...) - Use for elements that respond to touch/pointer.
.interactive() - Keep shapes consistent across related elements for a cohesive look.
- Gate with and provide a non-glass fallback.
#available(iOS 26, *)
- 优先使用原生Liquid Glass API而非自定义模糊效果。
- 当存在多个玻璃元素时,使用。
GlassEffectContainer - 在布局和视觉修饰符之后应用。
.glassEffect(...) - 为响应触摸/指针的元素使用。
.interactive() - 保持相关元素的形状一致,以实现连贯的视觉效果。
- 使用进行版本控制,并提供非玻璃效果的降级方案。
#available(iOS 26, *)
Review Checklist
评审检查清单
- Availability: present with fallback UI.
#available(iOS 26, *) - Composition: Multiple glass views wrapped in .
GlassEffectContainer - Modifier order: applied after layout/appearance modifiers.
glassEffect - Interactivity: only where user interaction exists.
interactive() - Transitions: used with
glassEffectIDfor morphing.@Namespace - Consistency: Shapes, tinting, and spacing align across the feature.
- 兼容性:存在并提供降级界面。
#available(iOS 26, *) - 组合方式:多个玻璃视图被包裹在中。
GlassEffectContainer - 修饰符顺序:在布局/外观修饰符之后应用。
glassEffect - 交互性:仅在存在用户交互的地方使用。
interactive() - 转场效果:结合使用
@Namespace实现形态转换。glassEffectID - 一致性:相关元素的形状、色调和间距保持一致。
Implementation Checklist
实现检查清单
- Define target elements and desired glass prominence.
- Wrap grouped glass elements in and tune spacing.
GlassEffectContainer - Use as needed.
.glassEffect(.regular.tint(...).interactive(), in: .rect(cornerRadius: ...)) - Use /
.buttonStyle(.glass)for actions..buttonStyle(.glassProminent) - Add morphing transitions with when hierarchy changes.
glassEffectID - Provide fallback materials and visuals for earlier iOS versions.
- 确定目标元素和所需的玻璃效果突出度。
- 将分组的玻璃元素包裹在中并调整间距。
GlassEffectContainer - 根据需要使用。
.glassEffect(.regular.tint(...).interactive(), in: .rect(cornerRadius: ...)) - 为操作按钮使用/
.buttonStyle(.glass)。.buttonStyle(.glassProminent) - 当视图层级变化时,使用添加形态转换效果。
glassEffectID - 为早期iOS版本提供替代材质和视觉效果。
Quick Snippets
快速代码片段
Use these patterns directly and tailor shapes/tints/spacing.
swift
if #available(iOS 26, *) {
Text("Hello")
.padding()
.glassEffect(.regular.interactive(), in: .rect(cornerRadius: 16))
} else {
Text("Hello")
.padding()
.background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 16))
}swift
GlassEffectContainer(spacing: 24) {
HStack(spacing: 24) {
Image(systemName: "scribble.variable")
.frame(width: 72, height: 72)
.font(.system(size: 32))
.glassEffect()
Image(systemName: "eraser.fill")
.frame(width: 72, height: 72)
.font(.system(size: 32))
.glassEffect()
}
}swift
Button("Confirm") { }
.buttonStyle(.glassProminent)直接使用以下模式,并根据需要调整形状/色调/间距。
swift
if #available(iOS 26, *) {
Text("Hello")
.padding()
.glassEffect(.regular.interactive(), in: .rect(cornerRadius: 16))
} else {
Text("Hello")
.padding()
.background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 16))
}swift
GlassEffectContainer(spacing: 24) {
HStack(spacing: 24) {
Image(systemName: "scribble.variable")
.frame(width: 72, height: 72)
.font(.system(size: 32))
.glassEffect()
Image(systemName: "eraser.fill")
.frame(width: 72, height: 72)
.font(.system(size: 32))
.glassEffect()
}
}swift
Button("Confirm") { }
.buttonStyle(.glassProminent)Resources
资源
- Reference guide:
references/liquid-glass.md - Prefer Apple docs for up-to-date API details.
- 参考指南:
references/liquid-glass.md - 优先查阅Apple文档获取最新的API细节。