2025-09-10 19:25:33 +08:00

90 lines
3.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
struct CustomLightSequenceAnimation: View {
// "123321123321"
private let baseSequence: [Int] = [1, 2, 3, 3, 2, 1, 1, 2, 3, 3, 2, 1]
@State private var currentLight: Int = 1 //
@State private var sequenceIndex: Int = 0 //
//
@State private var currentOpacity: CGFloat = 1.0
@State private var nextOpacity: CGFloat = 0.0
//
private let screenWidth = UIScreen.main.bounds.width
private let squareSize: CGFloat
private let imageSize: CGFloat
init() {
self.squareSize = screenWidth * 1.8 //
self.imageSize = squareSize / 3 // 1/3
}
// MARK: - SwiftUI
private struct CardBlindBackground: View {
var body: some View {
GeometryReader { geo in
let w = geo.size.width
let h = geo.size.height
ZStack {
//
RoundedRectangle(cornerRadius: 28)
.fill(
LinearGradient(
colors: [Color.white, Color.white.opacity(0.96)],
startPoint: .topLeading,
endPoint: .bottomTrailing
)
)
.shadow(color: Color.black.opacity(0.06), radius: 16, x: 0, y: 8)
.frame(width: w * 0.88, height: h * 0.88)
.position(x: w / 2, y: h / 2)
//
Circle()
.fill(Color.themePrimary.opacity(0.18))
.blur(radius: 40)
.frame(width: min(w, h) * 0.35, height: min(w, h) * 0.35)
.position(x: w * 0.25, y: h * 0.25)
//
Circle()
.fill(Color.orange.opacity(0.14))
.blur(radius: 50)
.frame(width: min(w, h) * 0.40, height: min(w, h) * 0.40)
.position(x: w * 0.75, y: h * 0.75)
//
RoundedRectangle(cornerRadius: 28)
.stroke(Color.white.opacity(0.35), lineWidth: 1)
.frame(width: w * 0.88, height: h * 0.88)
.position(x: w / 2, y: h / 2)
.blendMode(.overlay)
.opacity(0.7)
}
}
}
}
//
private var centerPosition: CGPoint {
CGPoint(x: screenWidth / 2, y: squareSize * 0.325)
}
var body: some View {
ZStack {
// SwiftUI
CardBlindBackground()
.frame(width: squareSize, height: squareSize)
.position(centerPosition)
}
}
}
//
struct CustomLightSequenceAnimation_Previews: PreviewProvider {
static var previews: some View {
CustomLightSequenceAnimation()
}
}