Communitygithub.com

液态玻璃设计系统

iOS 26 液态玻璃设计系统 — 动态玻璃材质,支持模糊、反射及交互形变,适用于 SwiftUI、UIKit 和 WidgetKit。在构建 iOS 26 液态玻璃 UI 时使用。

液态玻璃设计系统 是什么?

液态玻璃设计系统(Liquid Glass Design System)是专为 iOS 26 及以上版本打造的现代 UI 设计规范。它提供了一种动态玻璃材质,能够模糊背景内容、反射周围颜色与光线,并响应用户的触摸和指针交互。该技能覆盖 SwiftUI、UIKit 和 WidgetKit 三大平台,核心 API 包括 `glassEffect()` 修饰符、`GlassEffectContainer` 容器、`glassEffectID` 与 `glassEffectUnion` 用于形变过渡,以及 UIKit 中的 `UIGlassEffect` 和 `UIGlassContainerEffect` 类。WidgetKit 方面支持渲染模式检测、强调色分组和容器背景。使用此技能可以快速实现悬浮按钮、卡片、工具栏、形变动画和小组件一体化效果,并遵循统一的设计最佳实践,避免性能退化与视觉混乱。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/liquid-glass-design

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

液态玻璃设计系统 (iOS 26)

实现 Apple 液态玻璃(Liquid Glass)的模式 —— 一种动态材质,可模糊背后的内容,反射周围内容的颜色和光线,并对触摸和指针交互做出响应。涵盖 SwiftUI、UIKit 和 WidgetKit 集成。

何时激活

  • 构建或更新 iOS 26+ 应用,采用新的设计语言
  • 实现玻璃风格的按钮、卡片、工具栏或容器
  • 创建玻璃元素之间的形变过渡
  • 为小组件应用液态玻璃效果
  • 将现有的模糊/材质效果迁移到新的液态玻璃 API

核心模式 —— SwiftUI

基础玻璃效果

为任意视图添加液态玻璃的最简单方式:

Text("Hello, World!")
    .font(.title)
    .padding()
    .glassEffect()  // 默认:常规变体,胶囊形状

自定义形状和色调

Text("Hello, World!")
    .font(.title)
    .padding()
    .glassEffect(.regular.tint(.orange).interactive(), in: .rect(cornerRadius: 16.0))

关键自定义选项:

  • .regular —— 标准玻璃效果
  • .tint(Color) —— 添加颜色色调以突出显示
  • .interactive() —— 对触摸和指针交互做出响应
  • 形状:.capsule(默认)、.rect(cornerRadius:)、.circle

玻璃按钮样式

Button("Click Me") { /* 操作 */ }
    .buttonStyle(.glass)

Button("Important") { /* 操作 */ }
    .buttonStyle(.glassProminent)

多个元素的 GlassEffectContainer

始终将多个玻璃视图包裹在容器中,以获得更好的性能和形变:

GlassEffectContainer(spacing: 40.0) {
    HStack(spacing: 40.0) {
        Image(systemName: "scribble.variable")
            .frame(width: 80.0, height: 80.0)
            .font(.system(size: 36))
            .glassEffect()

        Image(systemName: "eraser.fill")
            .frame(width: 80.0, height: 80.0)
            .font(.system(size: 36))
            .glassEffect()
    }
}

spacing 参数控制合并距离 —— 距离越近的元素,其玻璃形状融合程度越高。

合并玻璃效果

使用 glassEffectUnion 将多个视图合并为一个玻璃形状:

@Namespace private var namespace

GlassEffectContainer(spacing: 20.0) {
    HStack(spacing: 20.0) {
        ForEach(symbolSet.indices, id: \.self) { item in
            Image(systemName: symbolSet[item])
                .frame(width: 80.0, height: 80.0)
                .glassEffect()
                .glassEffectUnion(id: item < 2 ? "group1" : "group2", namespace: namespace)
        }
    }
}

形变过渡

在玻璃元素出现/消失时创建平滑形变:

@State private var isExpanded = false
@Namespace private var namespace

GlassEffectContainer(spacing: 40.0) {
    HStack(spacing: 40.0) {
        Image(systemName: "scribble.variable")
            .frame(width: 80.0, height: 80.0)
            .glassEffect()
            .glassEffectID("pencil", in: namespace)

        if isExpanded {
            Image(systemName: "eraser.fill")
                .frame(width: 80.0, height: 80.0)
                .glassEffect()
                .glassEffectID("eraser", in: namespace)
        }
    }
}

Button("Toggle") {
    withAnimation { isExpanded.toggle() }
}
.buttonStyle(.glass)

水平滚动扩展到侧边栏下方

要使水平滚动内容延伸到侧边栏或检查器下方,请确保 ScrollView 内容到达容器的前缘/后缘。当布局延伸到边缘时,系统会自动处理侧边栏下方的滚动行为 —— 无需添加额外的修饰符。

核心模式 —— UIKit

基础 UIGlassEffect

let glassEffect = UIGlassEffect()
glassEffect.tintColor = UIColor.systemBlue.withAlphaComponent(0.3)
glassEffect.isInteractive = true

let visualEffectView = UIVisualEffectView(effect: glassEffect)
visualEffectView.translatesAutoresizingMaskIntoConstraints = false
visualEffectView.layer.cornerRadius = 20
visualEffectView.clipsToBounds = true

view.addSubview(visualEffectView)
NSLayoutConstraint.activate([
    visualEffectView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
    visualEffectView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
    visualEffectView.widthAnchor.constraint(equalToConstant: 200),
    visualEffectView.heightAnchor.constraint(equalToConstant: 120)
])

// 向 contentView 添加内容
let label = UILabel()
label.text = "Liquid Glass"
label.translatesAutoresizingMaskIntoConstraints = false
visualEffectView.contentView.addSubview(label)
NSLayoutConstraint.activate([
    label.centerXAnchor.constraint(equalTo: visualEffectView.contentView.centerXAnchor),
    label.centerYAnchor.constraint(equalTo: visualEffectView.contentView.centerYAnchor)
])

多个元素的 UIGlassContainerEffect

let containerEffect = UIGlassContainerEffect()
containerEffect.spacing = 40.0

let containerView = UIVisualEffectView(effect: containerEffect)

let firstGlass = UIVisualEffectView(effect: UIGlassEffect())
let secondGlass = UIVisualEffectView(effect: UIGlassEffect())

containerView.contentView.addSubview(firstGlass)
containerView.contentView.addSubview(secondGlass)

滚动边缘效果

scrollView.topEdgeEffect.style = .automatic
scrollView.bottomEdgeEffect.style = .hard
scrollView.leftEdgeEffect.isHidden = true

工具栏玻璃集成

let favoriteButton = UIBarButtonItem(image: UIImage(systemName: "heart"), style: .plain, target: self, action: #selector(favoriteAction))
favoriteButton.hidesSharedBackground = true  // 退出共享玻璃背景

核心模式 —— WidgetKit

渲染模式检测

struct MyWidgetView: View {
    @Environment(\.widgetRenderingMode) var renderingMode

    var body: some View {
        if renderingMode == .accented {
            // 着色模式:白色着色,主题玻璃背景
        } else {
            // 全彩模式:标准外观
        }
    }
}

视觉层次的强调色分组

HStack {
    VStack(alignment: .leading) {
        Text("Title")
            .widgetAccentable()  // 强调色组
        Text("Subtitle")
            // 主要组(默认)
    }
    Image(systemName: "star.fill")
        .widgetAccentable()  // 强调色组
}

着色模式中的图像渲染

Image("myImage")
    .widgetAccentedRenderingMode(.monochrome)

容器背景

VStack { /* 内容 */ }
    .containerBackground(for: .widget) {
        Color.blue.opacity(0.2)
    }

关键设计决策

决策理由
GlassEffectContainer 包裹性能优化,支持玻璃元素之间的形变
spacing 参数控制合并距离 —— 精细调整元素之间需要多近才能融合
@Namespace + glassEffectID在视图层次结构变化时启用平滑形变过渡
interactive() 修饰符显式选择触摸/指针反应 —— 并非所有玻璃都应该响应
UIKit 中的 UIGlassContainerEffect与 SwiftUI 相同的容器模式,保持一致性
小组件中的着色渲染模式当用户选择着色主屏幕时,系统应用着色玻璃效果

最佳实践

  • 始终使用 GlassEffectContainer 在对多个同级视图应用玻璃效果时 —— 它支持形变并提高渲染性能
  • 在其他外观修饰符(frame、font、padding)之后 应用 .glassEffect()
  • 仅在响应用户交互的元素(按钮、可切换项)上 使用 .interactive()
  • 在容器中仔细选择 spacing 以控制玻璃效果何时合并
  • 更改视图层次结构时使用 withAnimation 以启用平滑形变过渡
  • 在不同外观下测试 —— 浅色模式、深色模式以及着色/强调色模式
  • 确保无障碍对比度 —— 玻璃上的文本必须保持可读性

应避免的反模式

  • 不使用 GlassEffectContainer 而使用多个独立的 .glassEffect() 视图
  • 嵌套过多的玻璃效果 —— 会降低性能和视觉清晰度
  • 对每个视图都应用玻璃效果 —— 仅保留给交互式元素、工具栏和卡片
  • 在 UIKit 中使用圆角时忘记 clipsToBounds = true
  • 忽略小组件中的着色渲染模式 —— 会破坏着色主屏幕外观
  • 在玻璃后面使用不透明背景 —— 会抵消半透明效果

使用时机

  • 使用 iOS 26 新设计的导航栏、工具栏和标签栏
  • 浮动操作按钮和卡片式容器
  • 需要视觉深度和触摸反馈的交互式控件
  • 应与系统液态玻璃外观集成的小组件
  • 相关 UI 状态之间的形变过渡

Individual skills in this repo

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

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能