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

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

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

  1. struct ContentView: View {
  2. @State private var tabSelection = 1
  3. @EnvironmentObject var timerModel: TimerModel
  4. var body: some View
  5. {
  6. TabView(selection: $tabSelection) {
  7. DashboardView()
  8. .tag(1)
  9. TimerView()
  10. .tag(2)
  11. .environmentObject(timerModel)
  12. SettingsView()
  13. .tag(3)
  14. }
  15. .overlay(alignment: .bottom)
  16. {
  17. CustomTabView(tabSelection: $tabSelection)
  18. }
  19. }
  20. }
  21. struct ContentView_Previews: PreviewProvider {
  22. static var previews: some View
  23. {
  24. ContentView()
  25. .environmentObject(TimerModel())
  26. }
  27. }
  28. `
  29. @ViewBuilder
  30. func NewTimerView()->some View
  31. {
  32. VStack(spacing: 15) {
  33. Text("Change Timer Settings")
  34. .font(.title2.bold())
  35. .foregroundStyle(.black)
  36. .padding(.top, 10)
  37. etc content...
  38. }
  39. NewTimerView()
  40. .frame(maxHeight: .infinity, alignment: .bottom)
  41. .offset(y : timerModel.addNewTimer ? 0 : 600)
  42. .zIndex(timerModel.addNewTimer ? 1 : 0)
  43. }
  44. .animation(.easeInOut, value: timerModel.addNewTimer)

ztyzrc3y

ztyzrc3y1#

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

  1. var body: some View {
  2. VStack(spacing: 0) {
  3. TabView(selection: $tabSelection) {
  4. DashboardView()
  5. .tag(1)
  6. TimerView()
  7. .tag(2)
  8. .environmentObject(timerModel)
  9. SettingsView()
  10. .tag(3)
  11. }
  12. CustomTabView(tabSelection: $tabSelection)
  13. }
  14. }
展开查看全部

相关问题