ios 如何在我的自定义标签栏前面创建视图?它出现的时候不是在后面吗?

zf2sa74q  于 2023-10-21  发布在  iOS
关注(0)|答案(1)|浏览(98)

我需要我的第二个视图,我想按下按钮后出现在标签栏前面显示,而不是后面,因为它是。

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)

ztyzrc3y

ztyzrc3y1#

所选选项卡显示在自定义选项卡栏后面,因为选项卡栏显示在覆盖层中。
尝试使用VStack作为父容器:

var body: some View {
    VStack(spacing: 0) {
        TabView(selection: $tabSelection) {
            DashboardView()
                .tag(1)
            TimerView()
                .tag(2)
                .environmentObject(timerModel)
            SettingsView()
                .tag(3)

        }
        CustomTabView(tabSelection: $tabSelection)
    }
}

相关问题