Skip to content

Commit

Permalink
Flipper animation sample
Browse files Browse the repository at this point in the history
  • Loading branch information
TahaTesser committed Feb 7, 2025
1 parent 04a3fb6 commit ee3fa0d
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 2 deletions.
Binary file not shown.
21 changes: 21 additions & 0 deletions SwiftUIPlayground/Assets.xcassets/Joker.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Joker.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions SwiftUIPlayground/Assets.xcassets/Red_Deck.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Red_Deck.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion SwiftUIPlayground/Samples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,13 @@ public let samples: [String: AnyView] = [
title: "View", samples:
[
"Color Brightess": AnyView(ColorBrightnessSample()),
"Flipper Animation": AnyView(FlipperAnimationSample()),
]
)),
"NumbersDataBasicValues": AnyView(SamplesList(
title: "NumbersDataBasicValues", samples:
[
"NumberFormatter": AnyView(NumberFormatterSample()),
]
))
)),
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct NumberFormatterSample: View {
.font(.system(size: 80, weight: .bold))
.padding()
}

private func formatNumberAsWords(_ number: Int) -> String {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .spellOut
Expand Down
41 changes: 41 additions & 0 deletions SwiftUIPlayground/Samples/View/FlipperAnimationSample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// FlipperAnimationSample.swift
// SwiftUIPlayground
//
// Created by Taha Tesser on 05.01.2025.
//

import SwiftUI

struct FlipperAnimationSample: View {
@State private var timer: Timer?
@State private var flipped: Bool = false

var body: some View {
ZStack {
Image(.joker)
.rotation3DEffect(.degrees(flipped ? -180 : 0), axis: (x: 1.0, y: 0.0, z: 0.0))
.opacity(flipped ? 0 : 1)

Image(.redDeck)
.rotation3DEffect(.degrees(flipped ? 0 : 180), axis: (x: 1.0, y: 0.0, z: 0.0))
.opacity(flipped ? 1 : 0)
}
.onAppear {
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in

withAnimation(.spring(response: 0.6, dampingFraction: 0.7, blendDuration: 0.2)) {
flipped.toggle()
}
}
}
.onDisappear {
timer?.invalidate()
timer = nil
}
}
}

#Preview {
FlipperAnimationSample()
}

0 comments on commit ee3fa0d

Please sign in to comment.