我正在使用自定义 Tabbar 并实现了您可以在 iOS 的 App Store 上找到的相同动画,当您单击“今日视图”中的卡片时。
一旦卡片展开,我想隐藏标签栏。目前我用布尔变量隐藏它。但是当我点击其中一张卡片时,整个几何阅读器都会消失。
这是包含 Tabbar 和 HomeView 的类,其中实现了带有卡片的列表
struct AppCoordinator: View {
@State var index = 0
@State var showTabbar = true
var body: some View {
ZStack(alignment: .bottom) {
if self.index == 0 {
HomeView(showTabbar: self.$showTabbar)
.padding(.bottom, -10)
} else if self.index == 1 {
Text("Order View")
} else if self.index == 2 {
Text("Settings View")
}
CustomTabBar(index: self.$index)
.isHidden(!showTabbar)
}.edgesIgnoringSafeArea(.bottom)
}
}
这是几何阅读器所在的 HomeView
struct HomeView: View {
@ObservedObject var model = HomeViewModel()
@State var index = 0
@State var hero = false
@Binding var showTabbar: Bool
var body: some View {
ZStack(alignment: .bottom) {
VStack{
ScrollView(.vertical, showsIndicators: false) {
HomeTopMenue(index: $index)
.padding()
VStack(alignment: .center, spacing: 30) {
ForEach(0..<self.model.meals.count, id: \.self){i in
GeometryReader{g in
CardView(meal: self.$model.meals[i], hero: self.$hero)
.offset(y: self.model.meals[i].getExpanded() ? -g.frame(in: .global).minY : 0)
.opacity(self.hero ? (self.model.meals[i].getExpanded() ? 1 : 0) : 1)
.onTapGesture {
self.showTabbar.toggle()
withAnimation(.interactiveSpring(response: 0.5, dampingFraction: 0.8, blendDuration: 0)){
if !self.model.meals[i].getExpanded() {
self.hero.toggle()
if self.model.meals[i].expanded == nil {
self.model.meals[i].expanded = true
} else {
self.model.meals[i].expanded?.toggle()
}
}
}
}
}.frame(height: self.model.meals[i].getExpanded() ? UIScreen.main.bounds.height : 400)
}
}
}.statusBar(hidden: hero)
}
}
}
}