Ching 21ed5d55cb feat(view): 增加动画效果
增加发牌动效,增加倒计时动效

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

48 lines
1.1 KiB
Swift

//
// Pie.swift
// Memorize
//
// Created by ching on 2023/2/15.
//
import SwiftUI
struct Pie: Shape {
var startAngle: Angle
var endAngle: Angle
var clockwise = false
var animatableData: AnimatablePair<Double, Double> {
get {
AnimatablePair(startAngle.radians, endAngle.radians)
}
set {
startAngle = Angle.radians(newValue.first)
endAngle = Angle.radians(newValue.second)
}
}
func path(in rect: CGRect) -> Path {
let center = CGPoint(x: rect.midX, y: rect.midY)
let radius = min(rect.height, rect.width) / 2
let start = CGPoint(
x: center.x + radius * CGFloat(cos(startAngle.radians)),
y: center.y + radius * CGFloat(sin(startAngle.radians))
)
var p = Path()
p.move(to: center)
p.addLine(to: start)
p.addArc(
center: center,
radius: radius,
startAngle: startAngle,
endAngle: endAngle,
clockwise: !clockwise
)
p.addLine(to: center)
return p
}
}