Swift UI VStack对齐。按下键盘时使文本框出现在键盘上

在使用SwiftUI时,我在视图中将“ twitter”图像置于较高位置时遇到问题。我想使Twitter图片更高,使其更接近我的两个Blob图片,并在Twitter图片和“登录我的帐户”短语之间添加间距。另外,我正在尝试获取我的UITextfield,现在我猜想它只是文本字段,当在我的“登录到您的帐户短语”下方单击时,它会随键盘显示,但是现在显示在我的视图中。

请参阅附件。

Swift UI VStack对齐。按下键盘时使文本框出现在键盘上

    GeometryReader { (deviceSize: GeometryProxy) in

        ZStack {
            //Define a screen color
            LinearGradient (gradient: Gradient(colors:[Color(ColorsSaved.gitLabdark),Color(ColorsSaved.gitLabLight)]),startPoint: .leading,endPoint: .trailing)

                //Extend the screen to all edges
                .edgesIgnoringSafeArea(.all)
            Image("blobVectorLight")
                .resizable()
                .frame(width: deviceSize.size.height * (220/812) * 0.81,height: deviceSize.size.height * (220/812),alignment: .topTrailing)
                .frame(width: deviceSize.size.width,height:deviceSize.size.height,alignment: .topTrailing)
                .edgesIgnoringSafeArea(.all)

            Image("blobVectordark")
                .resizable()
                .frame(width: deviceSize.size.height * (208/812) * 0.74,height: deviceSize.size.height * (208/812),alignment: .topTrailing)
                // .overlay(Image("blobVectorLight"))
                .frame(width: deviceSize.size.width,alignment: .topTrailing)
                .edgesIgnoringSafeArea(.all)

            VStack{

                Image ("twitter")
                    .resizable()
                    .frame(width: deviceSize.size.height*(77/812)*2.078,height: deviceSize.size.height*(77/812))

                Text ("Sign into your account")
                    .foregroundColor(.white)

                TextField ("username")

            }
        }
    }
}

}
aabb5888157 回答:Swift UI VStack对齐。按下键盘时使文本框出现在键盘上

要向上移动任何元素,请使用:

.offset(y: -200.0)

要增加VStack中元素之间的间距,请这样声明:

VStack(spacing: 20.0) { //....

要使用TextField,您需要一个值来将其绑定到:

//outside the body declare:
@State private var username: String = ""

//and then inside the body:
TextField("Username",text: $username)
,

我只是总结您在这里应该做的所有事情:

           VStack(spacing: 50){

            Spacer()
            Image ("image")
                .resizable()
                .frame(width: deviceSize.size.height*(77/812)*2.078,height: deviceSize.size.height*(77/812))
            Spacer()
            Text ("Sign into your account")
                .foregroundColor(.white)

            TextField.init("Username",text: self.$userName)
            Spacer()
        }

在身体上方

   @State var userName: String = ""
   var body: some View {
  ......

希望您得到想要的东西。

本文链接:https://www.f2er.com/3031554.html

大家都在问