我在Swift UI中的TextField无法响应点击,无法输入文本,代码是否存在问题?

您好,我是具有快速UI的中级工程师。

当前,我在使用TextField()时遇到问题,它对单击不响应,因此键盘无法显示,

但是,当它是VStack中两个主要元素之一时,它确实会显示,但除此之外,它不起作用,

代码是否有问题?谁能为此找到解决方法或解决方法?

谢谢,英里

{

    @State var textField = ""

    var body: some View {

        returnJoinmodalContent()

    }

    func returnJoinmodalContent() -> some View{

        let accentColor = Color.blue

        return VStack(alignment: .center){
            HStack{
                Text("Join Game")
                    .bold()
                    .font(.largeTitle)
                    .padding()
                Spacer()
                Button(action:{
                    //self.hideModal()
                }){
                Image(systemName: "xmark.circle.fill")
                    .resizable()
                    .frame(width: 50,height: 50)
                    .foregroundColor(accentColor)
                    .padding()
                }
            }
            .padding(.bottom,170)

            VStack(alignment: .leading){
                TextField("Enter Game Code",text: self.$textField)
                    .font(.largeTitle)

                Rectangle()
                    .frame(height: 6)
                    .foregroundColor(accentColor)
            }
            .padding()
            HStack{
                Button(action:{
                    //self.joinGame()
                }){
                    ZStack{
                RoundedRectangle(cornerRadius: 90)
                    .frame(width: 200,height: 70)
                    .foregroundColor(accentColor)
                Text("Ready!")
                    .bold()
                    .font(.title)
                    .foregroundColor(Color.white)
                    }
                }
            }
            .padding(.vertical,20)
            HStack{
                Image(systemName: "info.circle")
                    .resizable()
                    .frame(width:60,height:60)
                    .foregroundColor(accentColor)

                Text("Ask your host for the game code,it can be found at the bottom of the player lobby")
                .padding()
                Spacer()

            }
            .padding(.top,60)
            .padding(.horizontal,20)

            Spacer()
        }
        .padding()
    }




}
javacoffin 回答:我在Swift UI中的TextField无法响应点击,无法输入文本,代码是否存在问题?

这似乎是swiftUI中难以追踪的事情之一。我发现问题是您的就绪按钮。更具体地说,标签是ZStack,以彩色的圆角矩形作为背景。如果将按钮的标签替换为以下内容,则文本字段应该是可选的。

Text("Ready!")
.bold()
.font(.title)
.foregroundColor(Color.white)
.frame(width: 200,height: 70)
.background(accentColor)
.mask(RoundedRectangle(cornerRadius: 90))
本文链接:https://www.f2er.com/2379982.html

大家都在问