Docs
Cards

Motion Card

A solid colour card that tilts with the device, catching a fixed light across its face and its glass chips, and settles flat when pressed.

$npx swiftpieces add MotionCard
Try it in the Playground Use it on a real screen, take it apart, remix it, and copy the SwiftUI. No account needed.
Free · MIT + Commons ClauseiOS 17.0+Liquid Glasscardmotiontiltcore-motionpressticket
Type
MotionCard
Files
MotionCard.swift
Depends on
Nothing (Apple frameworks only)
Version
2.3.0
  • Info.plist NSMotionUsageDescription: Tilts the card as you move the device, so the light and shadow follow how you hold it.
In a full screen · SwiftPieces ProCard DetailsA card screen with a card that catches the light and flips to its CVV, plus limits and controls.

Attitude-driven card with a fixed-light sheen, tracking shadow, and press feedback.

Notes

  • Core Motion roll and pitch are read at 60Hz relative to a neutral pose, so the card sits flat however the phone is held, then run through an exponential filter (15% per sample) that removes hand jitter without perceptible lag. The neutral pose starts where the phone is when updates begin and drifts toward the current pose over about ten seconds, so the card levels out again after the hand settles into a new grip.
  • The tilt follows the phone linearly up to 70% of maxAngle (about 25° of rotation), then meets rubber-band resistance that eases it toward maxAngle without ever reaching it, so the card slows into its limit instead of stopping dead. Nothing on the sensor path is animated, so the card stays with the hand.
  • Motion starts on appear and whenever scenePhase becomes .active while the card is on screen, and stops on disappear and in any other phase, so the sensors never run in the background or behind a pushed screen or another tab. They also stop when Reduce Motion turns on and start again, from flat, when it turns off. In the simulator the card is static with a fixed light.
  • Pass attitude: (-1...1 per axis) to drive the tilt yourself for previews, tests, or the simulator; it replaces device motion entirely.
  • Touch-down sinks the card to pressScale toward the finger, settles the tilt halfway to flat, tips the card down under the finger by up to 0.3 of maxAngle at an edge (3° by default) and tightens the shadow. The sheen and the shadow follow that lean like any other tilt. The press arrives on a tight spring with no overshoot and one light impact per touch-down, and lets go with a little give from the same lean.
  • A lift within 10pt runs action if one is set. Slide further and the card lets go on the quicker snap spring, with far less give than a lift, so it never lingers in a press that would not count; come back within 10pt and it presses again, without a second haptic. A touch the system cancels (a scroll or an alert taking over) lets go the same way.
  • Reduce Motion keeps the card flat: no device tilt, sink or lean. A press darkens the card slightly (lightens it in dark mode) and tightens its shadow instead, and lets go without overshoot. The haptic stays.
  • The motion source is a nested @Observable class marked fileprivate, because the macro's generated extension cannot see a private nested type.
  • v2: the card draws a solid block (style.fill, red by default) with dark ink, a soft-light sheen plus a faint far-side shade whose center moves opposite the tilt, as a reflection of a fixed light would, and a two-layer shadow that slides the same way and widens with the tilt. Pressing settles the tilt halfway to flat, tightens the shadow, and scales to pressScale. Disabled cards desaturate.
  • style: (MotionCard.Style) sets fill, foreground, sheen, shadowOpacity, and pressScale; cornerRadius now defaults to 26.
  • v2.2: notchRadius and notchPosition cut half-circle notches from both side edges, as on a ticket's tear line. They are real holes in the card: the page shows through, the sheen stops at their edge, the shadow follows them and they take no touches. notchRadius: 0, the default, cuts none.
  • v2.3: liquid glass. The card itself stays a solid block (it is content, not chrome), and everything you lay on it takes semibold type: the piece sets .fontWeight(.semibold) on its content. Caption chips on the card's face read as light liquid glass, as the example's "ADMIT ONE" and ticket number do: small capsules 12pt in from the edges and 28pt tall, so their ends are concentric with the 26pt corners. They tilt with the card (glass follows its small tilt cleanly), catch the same fixed light as its sheen, and keep the ticket's dark ink in either appearance. The card's shadow is cast from its outline alone, so glass on its face never takes that shadow as a dark halo. On iOS 26 they are Liquid Glass; before that a frosted material with a light rim, and a solid fill under Reduce Transparency.
  • The example is a film ticket with glass caption chips, semibold seat numerals and a dashed tear line between two 11pt notches at 64% of its height. The simulator has no attitude, so it drifts through a few poses on its own.
  • For a full card screen, see the Pro Card Details screen (payment-card).

Usage

MotionCardExample()
    .preferredColorScheme(.light)

Parameters

ParameterDescription
maxAngleMaximum tilt in degrees on each axis.
cornerRadiusCorner radius of the card surface (continuous).
attitudeOptional fixed tilt, -1...1 on each axis, that replaces device motion. Useful for previews, tests, and the simulator.
styleThe card's fill, ink, sheen, shadow, and press. .standard is a red block with dark ink.
actionOptional tap handler. The card always scales on press; this runs on a clean tap.
contentCard content, laid over the card's own surface. It inherits style.foreground and semibold type.

Install

Pick one. Run it from the folder that contains your .xcodeproj and the files land inside your app.

Terminal

$npx swiftpieces add MotionCard

Or ask your coding agent · Claude Code, Cursor or Xcode, once the MCP server is connected

>Add the SwiftPieces "Motion Card" piece to my app

Or copy the source above into your app.

New to SwiftUI?If you know React, CSS or Tailwind, SwiftUI is easier to pick up than it looks.Try real app patterns first

Building a whole app? See SwiftPieces Pro →

All cards →

Build it yourself: SwiftUI motion guide · SwiftUI cards guide · SwiftUI animations guide

On this page

SwiftPiecesPro

Build the whole app with one library.

Production-ready screens, whole flows, complete app templates, a Build Kit your agent follows and Pro remixing.

54 screens · 46 patterns · 48 flows · 12 templates · 31 Build Kit skills

Explore Pro