我需要我的第二个视图,我想按下按钮后出现在标签栏前面显示,而不是后面,因为它是。
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)
1条答案
按热度按时间ztyzrc3y1#
所选选项卡显示在自定义选项卡栏后面,因为选项卡栏显示在覆盖层中。
尝试使用
VStack
作为父容器: