โœจWheel of Fortune

SwiftUI โŸฉ Animations โŸฉ examples โŸฉ

import SwiftUI-

struct ContentView: View {
    
    // โญ๏ธ "keyframe" parameter
    @State private var angle = 0.0
    
    var body: some View {
        ZStack {
            // fortune wheel
            Image("wheel")
                .resizable()
                .scaledToFit()
                .rotationEffect(.degrees(angle))
                .onTapGesture { 
                    // โญ๏ธ custom timing curve (bezier curve)
                    withAnimation(.timingCurve(0, 0.8, 0.2, 1, duration: 5)){
                        // โญ๏ธ set new "keyframe"
                        angle += Double.random(in: 360 * 4 ..< 360 * 8)
                    }
                }
            
            // circle
            Circle()
                .fill(.secondary)
                .frame(width: 50)
                .shadow(radius: 5)
                
            // pointer
            Image(systemName: "arrowtriangle.up.fill")
                .shadow(radius: 5)
                .offset(y: -35)
        }
        .padding(8)
        .frame(width: 500, height: 300)
        .border(.secondary)
    }
}

Last updated