Flashcards are the core screen of almost every vocabulary app. Here is a small, dependency-free SwiftUI flip card you can paste into any project.
The idea
Two faces stacked in a ZStack. We rotate the whole card around the Y axis, and hide the face that is pointing away from the user. The back face is pre-rotated 180° so its text is not mirrored.
The code
import SwiftUI
struct FlipCard < Front : View , Back : View >: View { @Binding var isFlipped : Bool let front : Front let back : Back
init ( isFlipped : Binding < Bool > , @ViewBuilder front : ( ) -> Front , @ViewBuilder back : ( ) -> Back ) { _isFlipped = isFlipped self . front = front ( ) self . back = back ( ) }
var body : some View { ZStack { face ( front ) . opacity ( isFlipped ? 0 : 1 ) face ( back ) . rotation3DEffect ( . degrees ( 180 ) , axis : ( 0 , 1 , 0 ) ) . opacity ( isFlipped ? 1 : 0 ) } . rotation3DEffect ( . degrees ( isFlipped ? 180 : 0 ) , axis : ( 0 , 1 , 0 ) , perspective : 0.5 ) . animation ( .…