feat: 动画
This commit is contained in:
parent
08a82386da
commit
982c32cfdb
@ -293,6 +293,7 @@ struct BlindBoxView: View {
|
||||
@State private var aspectRatio: CGFloat = 1.0
|
||||
@State private var isPortrait: Bool = false
|
||||
@State private var displayImage: UIImage?
|
||||
@State private var showMedia = false
|
||||
|
||||
// 查询数据 - 简单查询
|
||||
@Query private var login: [Login]
|
||||
@ -868,22 +869,39 @@ struct BlindBoxView: View {
|
||||
ZStack {
|
||||
GIFView(name: "BlindOpen")
|
||||
.frame(width: 300, height: 300)
|
||||
.scaleEffect(scale)
|
||||
.opacity(showMedia ? 0 : 1) // 当显示媒体时隐藏GIF
|
||||
.onAppear {
|
||||
print("开始播放开启动画")
|
||||
// 不在这里准备媒体,等待动画完成
|
||||
// 初始缩放为1(原始大小)
|
||||
self.scale = 1.0
|
||||
|
||||
// 2.5秒后开始显示媒体内容
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
|
||||
// 准备并显示媒体
|
||||
if mediaType == .video {
|
||||
loadVideo()
|
||||
} else if mediaType == .image {
|
||||
loadImage()
|
||||
}
|
||||
|
||||
// 开始缩放动画
|
||||
withAnimation(.easeInOut(duration: 0.5)) {
|
||||
self.startScalingAnimation()
|
||||
// 1秒后开始全屏动画
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
withAnimation(.spring(response: 1.0, dampingFraction: 0.7)) {
|
||||
// 缩放到全屏
|
||||
self.scale = max(
|
||||
UIScreen.main.bounds.width / 300,
|
||||
UIScreen.main.bounds.height / 300
|
||||
) * 1.2
|
||||
|
||||
// 全屏后稍作停留,然后缩小回原始大小
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
withAnimation(.spring(response: 0.8, dampingFraction: 0.7)) {
|
||||
self.scale = 1.0
|
||||
|
||||
// 显示媒体内容
|
||||
self.showScalingOverlay = true
|
||||
if mediaType == .video {
|
||||
loadVideo()
|
||||
} else if mediaType == .image {
|
||||
loadImage()
|
||||
}
|
||||
|
||||
// 标记显示媒体,隐藏GIF
|
||||
self.showMedia = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -899,7 +917,8 @@ struct BlindBoxView: View {
|
||||
.compositingGroup()
|
||||
.padding()
|
||||
}
|
||||
if !showScalingOverlay {
|
||||
// 只在未显示媒体且未播放动画时显示文字
|
||||
if !showScalingOverlay && !showMedia {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
// 从变量blindGenerate中获取description
|
||||
Text(blindGenerate?.videoGenerateTime ?? "hhsdshjsjdhn")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user