View in English

  • Apple 开发者
    • 入门汇总

    探索“入门汇总”

    • 概览
    • 学习
    • Apple Developer Program

    及时了解最新动态

    • 最新动态
    • 开发者你好
    • 平台

    探索“平台”

    • Apple 平台
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    • App Store

    精选

    • 设计
    • 分发
    • 游戏
    • 配件
    • 网页
    • Home
    • CarPlay 车载
    • 技术

    探索“技术”

    • 概览
    • Xcode
    • Swift
    • SwiftUI

    精选

    • 辅助功能
    • App Intents
    • Apple 智能
    • 游戏
    • 机器学习与 AI
    • 安全性
    • Xcode Cloud
    • 社区

    探索“社区”

    • 概览
    • “与 Apple 会面交流”活动
    • 社区主导的活动
    • 开发者论坛
    • 开源

    精选

    • WWDC
    • Swift Student Challenge
    • 开发者故事
    • App Store 大奖
    • Apple 设计大奖
    • Apple Developer Centers
    • 文档

    探索“文档”

    • 文档库
    • 技术概述
    • 示例代码
    • 《人机界面指南》
    • 视频

    发布说明

    • 精选更新
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • Apple tvOS
    • Xcode
    • 下载

    探索“下载”

    • 所有下载
    • 操作系统
    • 应用程序
    • 设计资源

    精选

    • Xcode
    • TestFlight
    • 字体
    • SF Symbols
    • Icon Composer
    • 支持

    探索“支持”

    • 概览
    • 帮助指南
    • 开发者论坛
    • “反馈助理”
    • 联系我们

    精选

    • 《开发者账户帮助》
    • 《App 审核指南》
    • 《App Store Connect 帮助》
    • 即将实行的要求
    • 协议和准则
    • 系统状态
  • 快速链接

    • 活动
    • 新闻
    • 论坛
    • 示例代码
    • 视频
 

视频

打开菜单 关闭菜单
  • 专题
  • 所有视频
  • 关于

更多视频

  • 简介
  • 概要
  • 代码
  • 使用 SwiftUI 构建高级图形效果

    探索如何通过创造性地组合运用 SwiftUI 布局和图形 API 来打造丰富的自定体验。我们将介绍如何分解复杂的设计,并通过创意流程将简单的构建块串联起来。了解如何使用图层着色器进行绘制、利用时间线制作动画,并通过对齐参考线锚定视图。

    章节

    • 0:00 - Introduction
    • 1:40 - Design breakdown
    • 4:11 - Cover art and shader effects
    • 11:07 - Driving animation with time
    • 12:00 - Time-synced transcript view
    • 13:18 - Floating timestamps with alignment guides
    • 16:16 - Creative pipelines
    • 17:13 - Next steps

    资源

    • Alignment
    • Composing advanced graphics effects with SwiftUI
    • Shader
      • 高清视频
      • 标清视频

    相关视频

    WWDC24

    • 利用 SwiftUI 打造自定视觉效果
  • 搜索此视频…
    • 4:18 - Cover art image

      Image("CoverArt")
    • 4:24 - Blurred cover art image

      Image("CoverArt")
          .blur(radius: 30)
    • 7:09 - Applying layer effect in SwiftUI

      GeometryReader { proxy in
          CoverArtView()
              .layerEffect(
                  ShaderLibrary.backgroundWarp(),
                  maxSampleOffset: .zero
              )
      }
      .ignoresSafeArea()
    • 7:21 - Writing layer effect shader in Metal

      [[stitchable]] half4 backgroundWarp(
          float2 position, SwiftUI::Layer layer
      ) {
          return layer.sample(position);
      }
    • 7:39 - Metal shader with offset parameter

      [[stitchable]] half4 backgroundWarp(
          float2 position, SwiftUI::Layer layer,
          float2 offset
      ) {
          return layer.sample(position + offset);
      }
    • 7:55 - SwiftUI layer effect with offset parameter

      GeometryReader { proxy in
          CoverArtView()
              .layerEffect(
                  ShaderLibrary.backgroundWarp(
                     .float2(.init(x: 0, y: 0))
                  ),
                  maxSampleOffset: .zero
              )
      }
      .ignoresSafeArea()
    • 8:04 - SwiftUI layer effect with full-width offset

      GeometryReader { proxy in
          CoverArtView()
              .layerEffect(
                  ShaderLibrary.backgroundWarp(
                     .float2(.init(x: proxy.size.width, y: 0))
                  ),
                  maxSampleOffset: .zero
              )
      }
      .ignoresSafeArea()
    • 8:37 - SwiftUI layer effect with noise sampling

      GeometryReader { proxy in
          CoverArtView()
              .layerEffect(
                  ShaderLibrary.backgroundWarp(
                      .float2(proxy.size),
                      .image(Image("NoiseTexture"))
                  ),
                  maxSampleOffset: .zero
              )
      }
      .ignoresSafeArea()
    • 8:55 - Metal shader with noise sampling

      [[stitchable]] half4 backgroundWarp(
          float2 position, SwiftUI::Layer layer,
          float2 size, texture2d<half> noiseTex
      ) {
          constexpr sampler s(address::repeat, filter::linear);
          float2 uv = position / size;
      
          half4 n = noiseTex.sample(s, uv);
          float2 offset = (float2(n.r, n.g) - 0.5) * 200.0;
      
          return layer.sample(position + offset);
      }
    • 10:22 - Metal shader with domain warping

      [[stitchable]] half4 backgroundWarp(
          float2 position, SwiftUI::Layer layer,
          float2 size, texture2d<half> noiseTex
      ) {
          constexpr sampler s(address::repeat, filter::linear);
          float2 uv = position / size;
      
          half4 n = noiseTex.sample(s, uv);
      
          float2 q = float2(n.r, n.g);
          n = noiseTex.sample(s, uv + q);
      
          float2 offset = (float2(n.r, n.g) - 0.5) * 200.0;
      
          return layer.sample(position + offset);
      }
    • 11:16 - SwiftUI layer effect with static visual

      GeometryReader { proxy in
          CoverArtView()
              .layerEffect(
                  ShaderLibrary.backgroundWarp(
                      .float2(proxy.size),
                      .image(Image("NoiseTexture"))
                  ),
                  maxSampleOffset: .zero
              )
      }
      .ignoresSafeArea()
    • 11:37 - SwiftUI layer effect with animated visual

      @State private var startDate = Date.now
      
      TimelineView(.animation) { timeline in
          let elapsed = timeline.date.timeIntervalSince(
              startDate
          )
          CoverArtView()
              .layerEffect(
                  ShaderLibrary.backgroundWarp(
                      .float2(proxy.size),
                      .image(Image("NoiseTexture")),
                      .float(elapsed)
                  ),
                  maxSampleOffset: .zero
              )
      }
    • 12:15 - Basic transcript view

      ScrollView {
          LazyVStack(alignment: .leading, spacing: 12) {
              ForEach(sampleTranscript) { line in
                      .font(.title)
                      .fontWeight(.bold)
              }
          }
      }
    • 12:33 - Time-synced transcript view

      @State private var playback = PlaybackState()
      
      ScrollViewReader { scrollProxy in
          ScrollView {
              LazyVStack(alignment: .leading, spacing: 12) {
                  ForEach(sampleTranscript) { line in
                      Text(line.text)
                          .transcriptLineStyle(isCurrent: 
                              line.id == playback.currentLineIndex
                          )
                  }
              }
          }
          .onChange(of: playback.currentLineIndex, { _, i in
              scrollProxy.scrollTo(i, anchor: .center)
          })
      }
    • 13:53 - Overlay with center alignment

      Text(line.text)
           .overlay {
                Text(line.formattedTimestamp)
           }
    • 14:06 - Overlay with bottom leading alignment

      Text(line.text)
           .overlay(alignment: .bottomLeading) {
                Text(line.formattedTimestamp)
           }
    • 14:32 - Overlay with alignment guide override

      Text(line.text)
           .overlay(alignment: .bottomLeading) {
                Text(line.formattedTimestamp)
                    .alignmentGuide(.bottom) { $0[.top] }
           }
    • 0:00 - Introduction
    • A way of thinking about advanced graphics and layout in SwiftUI as a creative pipeline — a series of stages that take data in, transform it, and pass it along.

    • 1:40 - Design breakdown
    • Take a finished design and decompose it into pipeline stages. Working from a podcast app's existing UI — cover art, playback info, transcript text — see how each piece can be transformed and connected: a shader pipe converts cover art into a visualizer, a time pipe drives motion, and another time pipe syncs transcript scrolling.

    • 4:11 - Cover art and shader effects
    • Soften the cover art with a blur, then layer on shader effects. Learn how shaders run per pixel on the GPU and how SwiftUI exposes them through three modifiers — color, distortion, and layer effects — each with different inputs and trade-offs. Build a layer-effect 'background warp' shader that samples a noise texture for organic, per-pixel offsets.

    • 11:07 - Driving animation with time
    • Shaders are stateless — for animation, time has to come from outside. Use TimelineView to fire every frame with a timestamp, pass it into the shader, and watch the warp pattern flow as time advances.

    • 12:00 - Time-synced transcript view
    • Build the foreground transcript using Text views in a LazyVStack inside a ScrollView. Use the playback timestamp to highlight the current line and fade the rest, then use onChange to scroll the current line to center as playback progresses.

    • 13:18 - Floating timestamps with alignment guides
    • Position a small timestamp on the edge of the current line without resorting to manual offsets. Walk through how SwiftUI's alignment system pins views together at their alignment points, then use alignmentGuide to override an alignment semantically — moving the subview's bottom guide to its top edge so it floats neatly outside its container.

    • 16:16 - Creative pipelines
    • Step back and see the pattern: each stage's output becomes the next stage's input. The same approach extends beyond this podcast app — swap audio for gyroscope data, a twist shader for a ripple, or a scroll view for a freeform canvas — to compose your own advanced effects.

    • 17:13 - Next steps
    • Download the sample project, experiment with the shader, and look for opportunities in your own app where a small visual effect could make a big difference.

Developer Footer

  • 视频
  • WWDC26
  • 使用 SwiftUI 构建高级图形效果
  • 打开菜单 关闭菜单
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    打开菜单 关闭菜单
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    打开菜单 关闭菜单
    • 辅助功能
    • 配件
    • Apple 智能
    • App 扩展
    • App Store
    • 音频与视频 (英文)
    • 增强现实
    • 设计
    • 分发
    • 教育
    • 字体 (英文)
    • 游戏
    • 健康与健身
    • App 内购买项目
    • 本地化
    • 地图与位置
    • 机器学习与 AI
    • 开源资源 (英文)
    • 安全性
    • Safari 浏览器与网页 (英文)
    打开菜单 关闭菜单
    • 完整文档 (英文)
    • 部分主题文档 (简体中文)
    • 教程
    • 下载
    • 论坛 (英文)
    • 视频
    打开菜单 关闭菜单
    • 支持文档
    • 联系我们
    • 错误报告
    • 系统状态 (英文)
    打开菜单 关闭菜单
    • Apple 开发者
    • App Store Connect
    • 证书、标识符和描述文件 (英文)
    • 反馈助理
    打开菜单 关闭菜单
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program (英文)
    • Mini Apps Partner Program
    • News Partner Program (英文)
    • Video Partner Program (英文)
    • 安全赏金计划 (英文)
    • Security Research Device Program (英文)
    打开菜单 关闭菜单
    • 与 Apple 会面交流
    • Apple Developer Center
    • App Store 大奖 (英文)
    • Apple 设计大奖
    • Apple Developer Academies (英文)
    • WWDC
    阅读最近新闻。
    获取 Apple Developer App。
    版权所有 © 2026 Apple Inc. 保留所有权利。
    使用条款 隐私政策 协议和准则