Skip to content

Commit ee3fa0d

Browse files
committed
Flipper animation sample
1 parent 04a3fb6 commit ee3fa0d

File tree

8 files changed

+86
-2
lines changed

8 files changed

+86
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "Joker.jpg",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "Red_Deck.jpg",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
Loading

SwiftUIPlayground/Samples.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,13 @@ public let samples: [String: AnyView] = [
179179
title: "View", samples:
180180
[
181181
"Color Brightess": AnyView(ColorBrightnessSample()),
182+
"Flipper Animation": AnyView(FlipperAnimationSample()),
182183
]
183184
)),
184185
"NumbersDataBasicValues": AnyView(SamplesList(
185186
title: "NumbersDataBasicValues", samples:
186187
[
187188
"NumberFormatter": AnyView(NumberFormatterSample()),
188189
]
189-
))
190+
)),
190191
]

SwiftUIPlayground/Samples/NumbersDataBasicValues/NumberFormatterSample.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct NumberFormatterSample: View {
1313
.font(.system(size: 80, weight: .bold))
1414
.padding()
1515
}
16-
16+
1717
private func formatNumberAsWords(_ number: Int) -> String {
1818
let numberFormatter = NumberFormatter()
1919
numberFormatter.numberStyle = .spellOut
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// FlipperAnimationSample.swift
3+
// SwiftUIPlayground
4+
//
5+
// Created by Taha Tesser on 05.01.2025.
6+
//
7+
8+
import SwiftUI
9+
10+
struct FlipperAnimationSample: View {
11+
@State private var timer: Timer?
12+
@State private var flipped: Bool = false
13+
14+
var body: some View {
15+
ZStack {
16+
Image(.joker)
17+
.rotation3DEffect(.degrees(flipped ? -180 : 0), axis: (x: 1.0, y: 0.0, z: 0.0))
18+
.opacity(flipped ? 0 : 1)
19+
20+
Image(.redDeck)
21+
.rotation3DEffect(.degrees(flipped ? 0 : 180), axis: (x: 1.0, y: 0.0, z: 0.0))
22+
.opacity(flipped ? 1 : 0)
23+
}
24+
.onAppear {
25+
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
26+
27+
withAnimation(.spring(response: 0.6, dampingFraction: 0.7, blendDuration: 0.2)) {
28+
flipped.toggle()
29+
}
30+
}
31+
}
32+
.onDisappear {
33+
timer?.invalidate()
34+
timer = nil
35+
}
36+
}
37+
}
38+
39+
#Preview {
40+
FlipperAnimationSample()
41+
}

0 commit comments

Comments
 (0)