Menu

1 / 2

Build a 3D flip flashcard in SwiftUI (with VoiceOver support)

DEV Community: ios·Thunder·3 days ago
#SZhq1vuk
#devtoios#devto#dev#isflipped#back
Long article (553 words) — no AI summary yet.
Reading 0:00
15s threshold

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 ( .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.