【问题标题】:Custom Tab Bar SwiftUi [duplicate]自定义标签栏 SwiftUi [重复]
【发布时间】:2021-04-14 02:44:39
【问题描述】:

SwiftUi 正在学习新东西。我创建了一个标签栏,但是当键盘打开时,标签栏随着键盘上升。 我该如何解决。你能帮助我吗? 我想将标签栏固定到底部。 或者有什么东西可以让键盘到达页面顶部? 由于我不知道在哪里修复它,我不得不扔掉所有的代码。

struct ContentView: View {
  
  @State var selected = 0
  
  var body: some View {
      
      VStack{
        
        if self.selected == 0{
            Color.blue
        }
        else if self.selected == 1{
            Color.red
        }
        else if self.selected == 2{
            Color.pink
        }
        else if self.selected == 3{
            Color.green
        }
        else if self.selected == 4{
            Color.yellow
        }
        
        Spacer()
          
          ZStack(alignment: .top){
              
              BottomBar(selected: self.$selected)
                  .padding()
                  .padding(.horizontal, 22)
                  .background(CurvedShape())
              
              Button(action: {
                self.selected = 4
                  
              }) {
                  
                  Image(systemName:"heart.fill").renderingMode(.original).padding(18)
                  
              }.background(Color.yellow)
              .clipShape(Circle())
              .offset(y: -32)
              .shadow(radius: 5)
              
          }
          
          
      }.background(Color("Color").edgesIgnoringSafeArea(.top))
  }
 }

 struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
      ContentView()
  }
 }

 struct CurvedShape : View {
  
  var body : some View{
      
      Path{path in
          
          path.move(to: CGPoint(x: 0, y: 0))
          path.addLine(to: CGPoint(x: UIScreen.main.bounds.width, y: 0))
          path.addLine(to: CGPoint(x: UIScreen.main.bounds.width, y: 55))
          
          path.addArc(center: CGPoint(x: UIScreen.main.bounds.width / 2, y: 55), 
radius: 30, startAngle: .zero, endAngle: .init(degrees: 180), clockwise: true)
          
          path.addLine(to: CGPoint(x: 0, y: 55))
          
      }.fill(Color.white)
      .rotationEffect(.init(degrees: 180))
  }
 }

 struct BottomBar : View {
  
  @Binding var selected : Int
  
  var body : some View{
      
      HStack{
          
          Button(action: {
              
              self.selected = 0
              
          }) {
              
              Image(systemName:"lasso")
              
          }.foregroundColor(self.selected == 0 ? .black : .gray)
          
          Spacer(minLength: 12)
          
          
          Button(action: {
              
              self.selected = 1
              
          }) {
              
              Image(systemName: "trash")
              
          }.foregroundColor(self.selected == 1 ? .black : .gray)
          
          
          Spacer().frame(width: 120)
          
          Button(action: {
              
              self.selected = 2
              
          }) {
              
              Image(systemName:"person")
              
          }.foregroundColor(self.selected == 2 ? .black : .gray)
          .offset(x: -10)

          
          Spacer(minLength: 12)
          
          Button(action: {
              
              self.selected = 3
              
          }) {
              
              Image(systemName: "pencil")
              
          }.foregroundColor(self.selected == 3 ? .black : .gray)
      }
   }
  }

【问题讨论】:

    标签: ios swift swiftui


    【解决方案1】:

    设置

     .ignoresSafeArea(.keyboard)
    

    到内容视图。

    【讨论】:

    • 我想给页面之间的过渡效果,你有什么相关信息吗?@Raja Kishan
    猜你喜欢
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    相关资源
    最近更新 更多