Communitygithub.com

CharbelElBateh/personal-website

Apple 的介面設計方法——流暢、具物理感的動態——轉化為 Web 實作。適用於建構或審查手勢驅動的 UI、彈簧動畫、拖曳/滑動/Sheet 互動、動量與可中斷轉場、半透明材質與深度、字體排印(光學尺寸、字距、行距)、減少動態模式,或 Apple 風格介面背後的設計基礎(回饋、空間一致性、克制)。

personal-website 是什麼?

此技能將 Apple 的流暢介面設計原則——主要源自 WWDC 2018《設計流暢介面》(Designing Fluid Interfaces)等講座——轉化為 Web 開發者可直接運用的知識。它並非單純的動畫庫,而是一套圍繞「響應性、1:1 直接操作、中斷性與動量投映」等核心概念建立的心法。支援的平台包括所有現代瀏覽器,透過 CSS、Pointer Events、requestAnimationFrame 以及 Motion 或 Framer Motion 等彈簧動畫庫實現。技能文件提供具體的實作範例,例如即時回饋的 CSS 過渡、使用 setPointerCapture 的拖曳邏輯、基於指數衰減的動量投映函數、橡膠邊界效果,以及半透明材質與景深的設計細節。對於開發 Apple 風格 UI 的工程師來說,這是一份從 Apple 內部設計思維出發的具體操作指南。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/CharbelElBateh/personal-website/tree/HEAD/.claude/skills/apple-design

在你喜歡的 AI 中提問

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

說明文件

Apple 設計

初始回應

當此技能首次被調用且沒有特定問題時,僅回覆:

我已準備好協助您在 Web 上打造流暢、Apple 風格的介面,我的知識來源於 Apple 的 WWDC 設計講座,並已轉化為 Web 實作。

在使用者提問之前,請勿提供任何其他資訊。

Apple 如何打造那些不再像電腦、反而像身體自然延伸的介面。這些知識來自 Apple 的 WWDC 設計講座——主要是 《設計流暢介面》(WWDC 2018)——經過提煉並轉化為 Web 平台(CSS、Pointer Events、requestAnimationFrame、Motion/Framer Motion 等彈簧動畫庫)的實作。

核心主線:當動畫從螢幕上的當前數值開始、繼承使用者的速度、將動量向前投映、並能在任何瞬間被攔截和反向時,介面就會顯得栩栩如生。 彈簧動畫是實現這一切自然的關鍵工具,因為它們本質上就是可中斷且能感知速度的。

核心理念

「當我們讓介面與思考和移動方式同步時,神奇的事情發生了——它不再像一台電腦,而開始感覺像我們身體的自然延伸。」

一個介面要流暢,就必須像物理世界一樣:即時回應、連續移動、攜帶動量、在邊界產生阻力,並且能在運動途中被重新定向。以下所有原則都是為了更加接近這個目標。

Apple 將設計定義為服務四種人類需求:安全感/可預測性、理解、成就感、喜悅。 每一條規則都是為了服務其中一項。

1. 響應——消除延遲

一旦出現延遲,直接操作的感覺就會「斷崖式下跌」。響應是其他一切的基礎。

  • 在手指按下時回應,而不是在釋放時。 按鈕一經按下就應立即高亮。等待 click/觸摸抬起才顯示回饋會顯得死氣沉沉。
  • 對任何延遲保持警覺。 檢查防抖、人為計時器、過渡等待以及 ~300ms 的點擊延遲。任何輸入路徑上非必要的東西都是倒退。
  • 回饋必須在互動過程中持續呈現,而不只是在結束時。 對於拖曳、滑桿或抽屜元件,應在整個過程中 1:1 地根據指針更新 UI——絕不要在手勢完成後才進行動畫。
/* 回饋存在於按壓的瞬間 */
.button:active {
  transform: scale(0.97);
  transition: transform 100ms ease-out;
}

2. 直接操作——1:1 追蹤

「觸摸和內容應該一起移動。」

當使用者拖曳某個東西時,它必須緊貼手指——並且尊重抓取時的偏移量。在抓取時立即吸附到元素中心會立刻打破沉浸感。

  • 使用 Pointer Events 搭配 setPointerCapture,這樣即使指針移出元素邊界,追蹤也能繼續。
  • 記錄一個簡短的速度/位置歷史(最近幾次的 pointermove 事件),而不只是當前點——你會在釋放時需要速度資料。
el.addEventListener('pointerdown', (e) => {
  el.setPointerCapture(e.pointerId);
  const grabOffset = e.clientY - el.getBoundingClientRect().top; // 尊重抓取位置
  // ...記錄位置和時間戳歷史以供速度計算
});

3. 可中斷性——最重要的單一原則

「想法和手勢是同步發生的。」

每一個動畫都必須能在任何時刻被中斷和重新導向。使用者必須能夠在一個正在移動的元素飛到半空中時抓住它並反向,而無需等待動畫結束。一個正在關閉的模態框,如果使用者再次抓住它,就應該跟著手指移動——而不是先完成關閉再重新開啟。

  • 切勿在轉場期間鎖定輸入。
  • 永遠從表現層(當前的)數值開始動畫,而不是目標數值。 中斷時,讀取元素的即時螢幕變換,並從該點開始新的動畫。從邏輯/目標數值開始會導致可見的跳躍。
  • 對於任何由手勢驅動的動畫,避免使用 CSS transitions 和 @keyframes——它們無法在運動途中被平滑地抓取和反向。彈簧動畫預設從當前數值開始,這正是中斷所需要的。
  • 當手勢反轉時,應混合速度——不要硬切。 在反轉點用一個動畫取代另一個會產生速度不連續性,就像撞上一堵「磚牆」。能夠在重新設定目標時攜帶速度的彈簧動畫庫可以避免這個問題。(這就是 iOS 的加法動畫原生所做的;在 Web 上,選擇一個能從當前速度重新設定目標的彈簧動畫庫。)
  • 將 2D 運動分解為獨立 X 軸和 Y 軸的彈簧。 當 X 和 Y 方向的速度不同時,在 2D 距離上使用單一彈簧會導致不同步。

4. 行為重於動畫——使用彈簧

「把動畫想成是你和物體之間的對話,而不是由介面預先編寫好的腳本。」

預先腳本化、固定時長的動畫無法回應新的輸入。彈簧可以——新的輸入只需改變目標,運動就能保持連續。對於任何使用者可以觸摸到的東西,請使用彈簧。

Apple 刻意將物理三參數(質量/剛度/阻尼)替換為兩個更適合設計師的參數。請用這兩個參數思考:

  • 阻尼比(Damping ratio)——控制過衝。1.0 = 臨界阻尼,無彈跳,平穩穩定。< 1.0 = 過衝並震盪。數值越低越有彈性。
  • 響應時間(Response)——數值到達目標的速度,以秒為單位。數值越低反應越快。這不是「持續時間」——彈簧沒有固定的持續時間;其穩定時間是由參數自然產生的。

預設值:

  • 大多數 UI 從阻尼 1.0(臨界阻尼)開始——優雅且不分散注意力。
  • 僅當手勢本身帶有動量時(例如輕彈、拋擲、拖曳釋放),才加入彈跳(阻尼約 0.8)。一個剛淡入的選單有過衝感覺很奇怪;但你輕彈出去的一張卡片有過衝則感覺很自然。

Apple 實際使用的具體數值:

互動類型阻尼響應時間
移動/重新定位(例如畫中畫)1.00.4
旋轉0.80.4
抽屜 / Sheet0.80.3

Web 映射(Motion / Framer Motion): bounce + duration 的彈簧 API 與 Apple 的阻尼+響應非常接近。一個安全的預設風格是到處使用 damping: 1.0 的彈簧;保留彈性給由動量驅動的物理互動。

import { animate } from 'motion';

// 臨界阻尼預設(無過衝)
animate(el, { y: 0 }, { type: 'spring', bounce: 0, duration: 0.4 });

// 動量互動——因為前面有輕彈動作,所以帶一點彈性
animate(el, { y: target }, { type: 'spring', bounce: 0.2, duration: 0.4 });

5. 速度交接——拖曳與動畫之間的無縫銜接

當手勢結束時,動畫必須以手指的確切速度繼續,這樣拖曳和動畫之間才不會出現可見的斷層。這是區分「流暢」與「還行」的關鍵細節。

將指針的釋放速度作為彈簧的初始速度傳入。有些彈簧 API 需要相對速度——請用剩餘距離對其進行標準化:

相對速度 = 手勢速度 / (目標數值 − 當前數值)

範例:元素在 y=50,目標 y=150(還有 100px 要走),手指移動速度 50px/s → 初始彈簧速度 = 50 / 100 = 0.5。Framer Motion / Motion 直接接受絕對的 px/s 速度(透過 velocity 選項),所以通常你傳入原始值即可。

6. 動量投映——讓動畫朝著手勢要去的地方

「用小輸入產生大輸出。」

不要從釋放點吸附到最近的邊界。使用速度來投映最終靜止位置——就像滾動減速一樣——然後吸附到離該投影點最近的目標。這就是讓一個輕彈動作感覺像是把元素拋出去的原因。

Apple 的準確投影函數(來自《設計流暢介面》的範例程式碼):

// decelerationRate ≈ 0.998 為正常滾動感;0.99 為更乾脆
function project(initialVelocity /* px/s */, decelerationRate = 0.998) {
  return (initialVelocity / 1000) * decelerationRate / (1 - decelerationRate);
}

const projectedEndpoint = currentPosition + project(releaseVelocity);
const target = nearestSnapPoint(projectedEndpoint);   // 從投影中選擇目標
animateSpringTo(target, { velocity: releaseVelocity }); // 然後進行速度交接(§5)

注意:物理課本上的 v²/(2·decel) 公式並非 Apple 實際使用的——請使用上面的指數衰減形式。這是優秀的底部 Sheet 和輪播(Vaul、Embla)中的標準行為。

7. 空間一致性——對稱路徑、錨定原點

「如果某樣東西從一個方向消失,我們期望它從原來的地方出現。」

  • 進入和退出應沿同一路徑。 從右側滑入的面板必須從右側關閉。右進/底出會讓人感到脫節和困惑。
  • 將互動錨定到其來源。 選單、彈出視窗或 Sheet 應該從觸發它的元素處產生——將 transform-origin 設定為觸發器,這樣按鈕和內容之間的空間關係就一目了然了。(這與彈出視窗從其觸發器而非中心縮放的起源感知觀念相同。)
  • 在可逆轉場中鏡像緩動效果,使離開路徑與返回路徑匹配(對兩個方向使用反向的 cubic-bézier 控制點)。

8. 在手勢方向上給予提示

人類會從軌跡預測最終狀態。中間的運動應該預示事物將要前往的方向——控制中心模組「朝著你的手指向上向外生長」。讓中間幀指向結果,而不僅僅是盲目地內插到結果。

9. 橡皮筋效果——柔軟邊界

在邊緣處,應逐漸施加阻力,而非生硬停止。生硬停止讀起來像「凍結」;持續的阻力則讀起來像「有回應,但這裡已經到底了」。應用一種阻尼,隨著使用者拖曳超出邊界越遠,其強度逐漸增加。

// 超出邊界越遠,元素跟隨得越少——真實物體在停止前會減速
function rubberband(overshoot, dimension, constant = 0.55) {
  return (overshoot * dimension * constant) / (dimension + constant * Math.abs(overshoot));
}

10. 手勢設計細節(「感覺」檢查清單)

  • 點擊: 在觸碰按下時高亮(即時),在觸碰抬起時確認。在目標周圍加入約 10px 的遲滯/點擊區域,並允許透過拖離再拖回的方式取消。
  • 拖曳/滑動: 在提交方向之前,需要一個小的移動閾值(遲滯,約 10px),然後進行 1:1 追蹤。
  • 從第一次移動開始並行檢測所有可能的手勢,一旦意圖明確,就自信地取消失敗的那一個。避免使用只報告最終狀態的識別器(如 swipeleft 類型事件)——它們捨棄了你實現回饋所需的連續追蹤。
  • 最小化解歧義延遲。 雙擊檢測無可避免地會延遲單擊;只有在確實需要雙擊功能的地方才付出這個成本。

11. 幀級平滑

平滑度關乎的是幀中的內容,而不僅僅是幀率。

  • 保持每幀的位置變化低於感知閾值,以避免閃爍感。
  • 對於極快的運動,微妙的動態模糊/拉伸可以傳達速度,比生硬的銳利線條效果更好。
  • requestAnimationFrame 是 Web 上與顯示器同步的時鐘(Apple 使用 CADisplayLink)。僅動畫化對合成器友善的屬性——transform 和 opacity——並在即將發生運動的地方使用 will-change 進行提示。

12. 材質與深度——半透明傳達層級

Apple 使用半透明材質作為浮動的功能層,在不搶走注意力的情況下帶來結構感。在 Web 上,可以使用 backdrop-filter 來近似實作。

  • 將導覽列/工具欄/Sheet 建構成半透明圖層(backdrop-filter: blur() 加上半透明背景),讓內容在其下方滾動——而不是佔用固定區域的不透明條狀物。
  • 材質重量傳達層級: 較暗/較重的材質區分結構區域(側邊欄);較輕的材質將注意力吸引到互動元素(按鈕)。切勿將淺色半透明表面疊加在另一個上面——可讀性會崩潰。
  • 較大的表面應感覺更厚: 使用比小型晶片更強的模糊和更深的陰影。考慮情境感知陰影——在密集/文字內容上方使用較重的陰影以增加分離感,在簡單背景上方使用較輕的陰影。
  • 調暗以聚焦,分離以保持流暢。 一個模態任務將表面與調暗的遮罩配對,並將背景推後/向下。一個並行、非阻塞的面板則使用半透明和偏移,不使用遮罩,以免打斷流程。對於堆疊的 Sheet,請逐漸調暗並將每個父層推後。
  • 生動效果保持文字在變化背景上的可讀性。 在模糊/半透明表面上,不要使用純灰色文字——應使用更高對比度、稍微重一點的字重,並微幅增加字距。將顏色放在實心層上,而不是半透明前景上。
  • 使用滾動邊緣效果,而非硬分隔線。 取代在黏性標題下方使用 1px 邊框,改為在浮動鍍鉻與內容重疊處淡化一個小模糊/漸層遮罩。
  • 材質化,而不僅僅是淡入淡出。 對於玻璃/模糊表面,在進入和退出時同時對模糊半徑和縮放進行動畫處理,使該表面讀起來像一個真實的材質抵達,而不是單純的不透明度淡入淡出。
.toolbar {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid rgba(255, 255, 255, 0.4); /* 明亮的頂部邊緣 = 光線打在材質上 */
}

13. 多模態回饋——動畫 + 聲音 + 觸覺

組合感官的三條規則(來自《設計音頻-觸覺體驗》):

  1. 因果關係——回饋的成因必須顯而易見。在實際的因果事件發生時(例如開關翻轉、項目吸附到位)觸發它,並使其特性與動作的物理感相匹配。
  2. 和諧——視覺、聲音和觸覺必須在同一幀觸發。它們之間的延遲會破壞沉浸感。不要讓一…

Individual skills in this repo

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

CharbelElBateh/personal-website

Build animations in React Native and Expo, making the decisions in the order that determines whether they feel right — should it animate, which thread it runs on, which properties, spring or timing, how the gesture hands off, how it degrades. Writes the implementation with Reanimated, Gesture Handler, Expo Router and expo-haptics. Use when animating anything in an Expo app, adding gestures, sheets, screen transitions, press feedback or haptics, or fixing motion that stutters on device. For web animation use `animate`.

CharbelElBateh/personal-website

Build an animation from scratch, making the decisions in the order that determines whether it feels right — should it animate at all, what purpose, which tool, which properties, which curve and duration, how it interrupts, how it exits. Writes the implementation. Use when asked to animate something, add motion, make a component feel alive, or build a transition. For critiquing existing motion use review-animations; for auditing a whole codebase use improve-animations.

CharbelElBateh/personal-website

Reverse-lookup glossary that turns a vague description of a web animation or motion effect into its exact term ("the bouncy thing when a popover opens" → Pop in; "the iOS rubber-band scroll" → Rubber-banding). Use when the user asks "what's it called when…", or describes a motion effect without knowing its name and wants the right word to prompt an AI or designer with. For naming an effect, not designing or building one.

CharbelElBateh/personal-website

Guide to Sonner, the React toast library — install and wire up the Toaster, pick the right toast() call, promise and loading toasts, updating, dismissing and persisting toasts, styling, theming and icons, positioning and multiple toasters. Use when working with Sonner or troubleshooting it — toasts that don't appear, appear twice, lose their styles, ignore Tailwind classes, sit behind a modal, or don't follow dark mode.

CharbelElBateh/personal-website

Try to break a piece of UI by feeding it worst-case data — long names, unbreakable emails, one-letter names, missing fields, huge counts, zero items, long labels, non-Latin text, emoji, extreme numbers — then render it behind a "Demo data / Worst case" toggle and report everything that broke, with the fix for each. Use when the user asks to stress-test, break, or find edge cases in a component or screen, or to "try the worst case". For visual design critique use emil-design-eng; for motion use review-animations.

CharbelElBateh/personal-website

This skill encodes Emil Kowalski's philosophy on UI polish, component design, animation decisions, and the invisible details that make software feel great.

CharbelElBateh/personal-website

Search a codebase or UI for places that don't animate but should, and reject everything that shouldn't. Read-only; it proposes motion with exact values, it does not implement it. Use when the user asks "what could be animated here?" or wants to "make this feel more alive". For fixing existing animations, use improve-animations or review-animations instead.

CharbelElBateh/personal-website

Survey a codebase's animation and motion code as a senior motion advisor, then produce a prioritized audit and self-contained implementation plans for other agents (or cheaper models) to execute. Read-only on source code — it plans improvements, it does not apply them. Use when the user asks to "improve the animations", "audit the motion", "make this app feel better", or wants a roadmap of animation fixes rather than a review of a single diff.

CharbelElBateh/personal-website

Make a web app feel native on a phone — the small CSS and meta-tag fixes that separate "a website in a browser" from something that feels installed. Covers sticky hover states, tap highlight flashes, the 100vh bug, inputs that zoom the page, laggy taps, pull-to-refresh hijacking scroll, content under the notch, long-press selecting button text, carousels that scroll the wrong way, mismatched status bars, and the rule that you test on real hardware. Use when a web app is being built for or reviewed on mobile, when something "works in Chrome but feels wrong on my phone", when building a PWA, a bottom sheet, a carousel, a full-screen layout, or any touch interaction. For motion itself use animate; for React Native use animate-expo.

CharbelElBateh/personal-website

Pick the right library for a given frontend task from a curated, opinionated list — numbers, OTP inputs, charts, command menus, virtualization, drag and drop, toasts, state, styling, and more. Only runs when explicitly invoked; it does not trigger on its own.

CharbelElBateh/personal-website

Build multiple genuinely different versions of a UI piece you describe, rendered behind a visual picker so you can flip through them live and promote the one that feels right. Only runs when explicitly invoked; it does not trigger on its own.

CharbelElBateh/personal-website

Reviews animation and motion code against a high craft bar derived from Emil Kowalski's design engineering philosophy. Default to flagging; approval is earned.

CharbelElBateh/personal-website

How to write modern Swift well — modeling with value types, Swift 6 data-race safety and approachable concurrency (@concurrent, main-actor-by-default, actors, task groups), protocols and generics (some vs any), API design, performance and ARC, Swift Testing, macros, and the modern language features agents don't know about yet. Use when writing, reviewing, or migrating Swift, or when a concurrency error, a hang, a data race, a retain cycle, or a performance problem needs fixing.

相關技能