I need to my second view that I want to appear after button pressed displayed in front of Tab Bar, not behind as it is.
struct ContentView: View {
@State private var tabSelection = 1
@EnvironmentObject var timerModel: TimerModel
var body: some View
{
TabView(selection: $tabSelection) {
DashboardView()
.tag(1)
TimerView()
.tag(2)
.environmentObject(timerModel)
SettingsView()
.tag(3)
}
.overlay(alignment: .bottom)
{
CustomTabView(tabSelection: $tabSelection)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View
{
ContentView()
.environmentObject(TimerModel())
}
}
`
@ViewBuilder
func NewTimerView()->some View
{
VStack(spacing: 15) {
Text("Change Timer Settings")
.font(.title2.bold())
.foregroundStyle(.black)
.padding(.top, 10)
etc content...
}
NewTimerView()
.frame(maxHeight: .infinity, alignment: .bottom)
.offset(y : timerModel.addNewTimer ? 0 : 600)
.zIndex(timerModel.addNewTimer ? 1 : 0)
}
.animation(.easeInOut, value: timerModel.addNewTimer)
2
Answers
Because when I had overlay there, I have capsule shape of Tab Bar. I need second view appear in front of it.
The selected tab is appearing behind the custom tab bar, becuase the tab bar is being shown in an overlay.
Try using a
VStack
as the parent container instead: