feat: 样式调整

This commit is contained in:
jinyaqiu 2025-08-27 18:20:02 +08:00
parent e0bc4ec5c9
commit 9b76b341f2

View File

@ -7,6 +7,37 @@ extension Notification.Name {
} }
// MARK: - // MARK: -
struct VisualEffectView: UIViewRepresentable {
var effect: UIVisualEffect?
func makeUIView(context: Context) -> UIVisualEffectView {
let view = UIVisualEffectView(effect: nil)
// Use a simpler approach without animator
let blurEffect = UIBlurEffect(style: .systemUltraThinMaterialLight)
// Create a custom blur effect with reduced intensity
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.alpha = 0.3 // Reduce intensity
// Add a white background with low opacity for better frosted effect
let backgroundView = UIView()
backgroundView.backgroundColor = UIColor.white.withAlphaComponent(0.1)
backgroundView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.contentView.addSubview(backgroundView)
view.contentView.addSubview(blurView)
blurView.frame = view.bounds
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
return view
}
func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
// No need to update the effect
}
}
struct BlindBoxView: View { struct BlindBoxView: View {
@State private var showLottieAnimation = true // Lottie @State private var showLottieAnimation = true // Lottie
@State private var showScalingOverlay = false @State private var showScalingOverlay = false
@ -14,6 +45,8 @@ struct BlindBoxView: View {
@State private var mediaToShow: MediaType? @State private var mediaToShow: MediaType?
@State private var videoPlayer: AVPlayer? @State private var videoPlayer: AVPlayer?
@State private var showControls = false // Add this line for controlling visibility @State private var showControls = false // Add this line for controlling visibility
@State private var aspectRatio: CGFloat = 1.0
@State private var isPortraitVideo: Bool = false
private func startScalingAnimation() { private func startScalingAnimation() {
// Start from 10% size // Start from 10% size
@ -27,12 +60,26 @@ struct BlindBoxView: View {
} }
private func loadVideo() { private func loadVideo() {
// Replace with your actual video URL guard let url = URL(string: "https://cdn.fairclip.cn/files/7329556154558844929/doubao-seedance-1-0-lite-i2v-2100199406-02174750234303300000000000000000000ffffac15403eacd2fe.mp4") else { return }
if let url = URL(string: "https://cdn.fairclip.cn/files/7342843896868769793/飞书20250617-144935.mp4") {
let player = AVPlayer(url: url) let asset = AVAsset(url: url)
player.isMuted = true // Mute the video let playerItem = AVPlayerItem(asset: asset)
self.videoPlayer = player let player = AVPlayer(playerItem: playerItem)
//
let videoTracks = asset.tracks(withMediaType: .video)
if let videoTrack = videoTracks.first {
let size = videoTrack.naturalSize.applying(videoTrack.preferredTransform)
let width = abs(size.width)
let height = abs(size.height)
//
aspectRatio = width / height
isPortraitVideo = height > width
} }
player.isMuted = true
self.videoPlayer = player
} }
var body: some View { var body: some View {
@ -69,7 +116,7 @@ struct BlindBoxView: View {
.position(x: UIScreen.main.bounds.width / 2, .position(x: UIScreen.main.bounds.width / 2,
y: UIScreen.main.bounds.height * 0.325) y: UIScreen.main.bounds.height * 0.325)
.opacity(showScalingOverlay ? 0 : 1) .opacity(showScalingOverlay ? 0 : 1)
.animation(.easeOut(duration: 0.5), value: showScalingOverlay) .animation(.easeOut(duration: 1.5), value: showScalingOverlay)
} }
if !showScalingOverlay { if !showScalingOverlay {
@ -86,9 +133,9 @@ struct BlindBoxView: View {
maxHeight: UIScreen.main.bounds.height * 0.65 maxHeight: UIScreen.main.bounds.height * 0.65
) )
.opacity(showScalingOverlay ? 0 : 1) .opacity(showScalingOverlay ? 0 : 1)
.animation(.easeOut(duration: 0.5), value: showScalingOverlay) .animation(.easeOut(duration: 1.5), value: showScalingOverlay)
.offset(y: showScalingOverlay ? -100 : 0) .offset(y: showScalingOverlay ? -100 : 0)
.animation(.easeInOut(duration: 0.5), value: showScalingOverlay) .animation(.easeInOut(duration: 1.5), value: showScalingOverlay)
} }
.frame(maxWidth: .infinity, maxHeight: .infinity) .frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.themeTextWhiteSecondary) .background(Color.themeTextWhiteSecondary)
@ -98,18 +145,28 @@ struct BlindBoxView: View {
// Scaling Overlay // Scaling Overlay
if showScalingOverlay { if showScalingOverlay {
ZStack { ZStack {
// Frosted glass background with custom transparency
VisualEffectView(effect: UIBlurEffect(style: .systemUltraThinMaterialLight))
.edgesIgnoringSafeArea(.all)
// Video Player // Video Player
if let player = videoPlayer { if let player = videoPlayer {
ZStack(alignment: .topLeading) { ZStack(alignment: .topLeading) {
VideoPlayer(player: player) VideoPlayer(player: player)
.aspectRatio(contentMode: .fill) .aspectRatio(contentMode: .fill)
.frame(width: UIScreen.main.bounds.width * scale, .frame(
height: UIScreen.main.bounds.height * scale) width: isPortraitVideo ?
UIScreen.main.bounds.height * scale * 1/aspectRatio :
UIScreen.main.bounds.width * scale,
height: isPortraitVideo ?
UIScreen.main.bounds.height * scale :
UIScreen.main.bounds.width * scale * 1/aspectRatio
)
.clipped() .clipped()
.opacity(scale == 1 ? 1 : 0.7) .opacity(scale == 1 ? 1 : 0.7)
.contentShape(Rectangle()) // Make entire area tappable .contentShape(Rectangle())
.onTapGesture { .onTapGesture {
withAnimation(.easeInOut(duration: 0.3)) { withAnimation(.easeInOut(duration: 0.1)) {
showControls.toggle() showControls.toggle()
} }
} }
@ -158,10 +215,10 @@ struct BlindBoxView: View {
} }
} }
.frame(maxWidth: .infinity, maxHeight: .infinity) .frame(maxWidth: .infinity, maxHeight: .infinity)
.animation(.easeInOut(duration: 3.0), value: scale) .animation(.easeInOut(duration: 1.0), value: scale)
.ignoresSafeArea() .ignoresSafeArea()
.onTapGesture { .onTapGesture {
withAnimation(.easeInOut(duration: 0.3)) { withAnimation(.easeInOut(duration: 0.1)) {
showControls.toggle() showControls.toggle()
} }
} }