Skip to content

Commit

Permalink
[Fix] fix animation bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
crazysteeaam committed May 7, 2024
1 parent 169c20c commit b66bcbd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
11 changes: 8 additions & 3 deletions VisionDashBoard/HomePageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import SwiftUI

struct HomePageView: View {
// 状态变量,用于控制RightArea的显示
@State private var isRightAreaVisible = true
@State private var isRightAreaVisible = false

var body: some View {
GeometryReader { geometry in
HStack {
HStack(alignment:.center, spacing: 0) {
LeftArea()
.frame(width: isRightAreaVisible ? geometry.size.width * 0.48 : geometry.size.width * 0.75)
.animation(.default, value: isRightAreaVisible)
Button(action: {
// 切换RightArea的显示状态
withAnimation { // 添加动画
isRightAreaVisible.toggle()

}
}) {
Image(systemName: "share")
Expand All @@ -27,9 +30,11 @@ struct HomePageView: View {
.frame(width: 44, height: 44)
if isRightAreaVisible {
RightArea()
.transition(.slide) // 使用滑动效果作为过渡动画
.frame(width: geometry.size.width * 0.5) // Adjust the width of RightArea
.transition(.slide) // 使用滑动效果作为过渡动画
}
}
.frame(width: geometry.size.width, alignment: .leading)
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions VisionDashBoard/LeftArea.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import SwiftUI

struct LeftArea: View {
var body: some View {

GeometryReader { geometry in
VStack {
VStack {
ProgressCardView()
.background(.ultraThinMaterial)
// .opacity(0.5)
Expand All @@ -32,6 +31,10 @@ struct LeftArea: View {
.padding(20)
}
}
.onAppear {
print("LeftArea Width: \(geometry.size.width)")
print("LeftArea Height: \(geometry.size.height)")
}
}
.frame(minWidth: 800, minHeight: 1100)
}
Expand Down
4 changes: 4 additions & 0 deletions VisionDashBoard/RightArea.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ struct RightArea: View {
.cornerRadius(40)
.padding(20)
}
.onAppear {
print("RightArea Width: \(geometry.size.width)")
print("RightArea Height: \(geometry.size.height)")
}
.frame(width: geometry.size.width, height: geometry.size.height)
}
}
Expand Down

0 comments on commit b66bcbd

Please sign in to comment.