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