cs193p-memorize/Memorize/Cardify.swift
Ching 21ed5d55cb feat(view): 增加动画效果
增加发牌动效,增加倒计时动效

Signed-off-by: Ching <loooching@gmail.com>
2023-02-16 23:21:20 +08:00

42 lines
998 B
Swift

//
// Cardify.swift
// Memorize
//
// Created by ching on 2023/2/15.
//
import SwiftUI
struct Cardify: AnimatableModifier {
init(isFaceUp: Bool) {
self.rotation = isFaceUp ? 0 : 180
}
var animatableData: Double {
get { rotation }
set { rotation = newValue }
}
var rotation: Double
func body(content: Content) -> some View {
ZStack {
let shape = RoundedRectangle(cornerRadius: const.DrawingConstants.cornerRadius)
if rotation < 90 {
shape.fill().foregroundColor(.white)
shape.strokeBorder(lineWidth: const.DrawingConstants.lineWidth)
} else {
shape.fill()
}
content
.opacity(rotation < 90 ? 1 : 0)
}
.rotation3DEffect(Angle.degrees(rotation), axis: (x: 0, y: 1, z: 0))
}
}
extension View {
func cadify(isFaceUp: Bool) -> some View {
modifier(Cardify(isFaceUp: isFaceUp))
}
}