Docs
Cards

Flip Card

A two-sided card you flip by tap or drag, scrubbing the turn and carrying the flick into the landing, with a lift and a moving shadow.

$npx swiftpieces add FlipCard
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 Glasscardflipdrag3dspringflashcard
Type
FlipCard
Files
FlipCard.swift
Depends on
Nothing (Apple frameworks only)
Version
2.2.0
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.

Two-sided card with tap-to-flip and drag-to-flip.

Notes

  • One DragGesture(minimumDistance: 0) handles everything: touch-down tilts the card toward the finger and sinks it to 0.97, an 8pt sideways move turns into a scrub where the full card width equals 180°, and a lift without movement is a tap. The press arrives on a tight spring with no overshoot and lets go with a little give. Only the press is animated, so the scrub is directly under the finger from its first frame.
  • Release commits when predictedEndTranslation projects past 90° in either direction, so a flick finishes the flip and a slow drag that stops short snaps back. Either way the card carries the flick's speed into the landing, so it turns straight through instead of stalling at lift-off, then swings past the face it lands on and settles back: about 8° after a turn from rest, and 13° to 20° after a hard flick. The release speed is capped, so even the hardest flick settles within about 20° instead of slinging further past. Past a half turn the scrub meets rubber-band resistance that grows the further you pull, easing toward 30° past it without ever hitting a wall.
  • While a finger turns it, the card lifts off the page even face-on: the shadow eases up as you pick it up and settles back down with the landing. Catch the card while it is still landing and it finishes that landing under your finger instead of jumping. A touch the system cancels turns the card back to the face it started on without committing.
  • Each face darkens with brightness as it turns edge-on and hides past 90°; the back is pre-rotated by -180° so it lands unmirrored. The shadow slides opposite the lifted edge and widens mid-flip.
  • The angle accumulates (0, 180, 360...) so repeated flips keep rotating the same way; isFlipped: stays in sync in both directions. A tap, the VoiceOver action and the binding turn the card a little slower than a release, since they start from rest, and a second tap mid-turn carries straight on into the next half turn.
  • A light impact fires on touch-down and a soft impact as the visible face changes. Reduce Motion replaces the rotation with a crossfade that the drag still scrubs, keeps the card flat, lands without overshoot, and shades the faces on press (darker in light mode, lighter in dark) instead of tilting and sinking them. The haptics stay.
  • v2: the card lifts 6% toward you at the edge-on point, sits on a layered shadow (a tight contact shadow plus a soft key shadow that slides off the raised edge), a soft-light band crosses each face as it turns, and the scrub rubber-bands past a half turn. Touch-down gives a light impact.
  • style: (FlipCard.Style) tunes cornerRadius, shadow/shadowOpacity (tripled in dark mode), lift, pressScale, pressTilt, shading, and the flip hint (hint, hintTint). onFlip: reports each committed flip. A disabled card dims and ignores touches.
  • v2.2: liquid glass. The faces stay yours (they are content, not chrome), and everything on them takes semibold type: the piece sets .fontWeight(.semibold) over both faces. Style(hint: true) adds the card's glass: a flip hint, a small liquid glass pill at the top centre of the card, on the axis it turns about, with a faint slot for each face and a signal dot (hintTint) over the face showing. The dot follows the drawn angle, so it slides under a scrub and lands on the turn's own spring, and mid-turn it smears along the pill like a drop on the move. The pill never turns with the faces: Liquid Glass can't follow a half turn in 3D (it flattens mid-flip), so it stays flat over both faces, lifts toward you with the card mid-turn and tips with a press, and the card's shadow never falls on it. On the axis it stays over the card the whole way round. Under Reduce Motion the dot slides without smearing. Off by default; keep the top centre of your faces clear for it.
  • Keep glass off the faces themselves, for the same reason: draw badges on a face as part of it. The example's "PORTUGUESE", "3 / 12" and "MEANING" badges are light chips 12pt in from the edges and 28pt tall, so their ends are concentric with the 26pt corners, level with the hint and in line with the face's text.
  • The example is a vocabulary flashcard: a butter front with a large word and a sky back with the meaning, each with its light badges, and the flip hint on. The preview shows the card alone, with no surrounding UI.
  • For a full card screen with number masking and controls, see the Pro Card Details screen (payment-card).

Usage

FlipCardExample()
    .preferredColorScheme(.light)

Parameters

ParameterDescription
isFlippedOptional binding to drive the flip externally. Leave nil to let the card manage its own state; taps and drags still update the binding when one is passed.
styleDepth, lift, press, and shading tuning. .standard uses the house values; the faces bring their own color.
onFlipCalled after a flip commits, with true when the back is now showing.
frontFront face. Give it its own shape and surface; the card only rotates, lifts, shades, and shadows it. Text
backBack face, shown after the flip. It is pre-rotated so text is never mirrored.

Install

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

Terminal

$npx swiftpieces add FlipCard

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

>Add the SwiftPieces "Flip 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