ios – Swift XCode Web page Shifting Up With Keyboard

ios – Swift XCode Web page Shifting Up With Keyboard


I’ve the beneath code at any time when I click on onto the TextField the web page appears to maneuver up which I’m not wanting I perceive having it a scroll view can assist.. However I’m not wanting that any recommendation could be nice.

I’ve tried a number of strategies however nothing appears to be working for me other than the scroll which I do not need, searching for a static I do not thoughts if the keyboard covers the content material

import SwiftUI

struct WESOffHiresView: View {
    @Surroundings(.presentationMode) var presentationMode
    @State personal var showAlert = false
    @State personal var jobNumber = ""
    @State personal var siteName = ""
    @State personal var consultant = ""
    @State personal var offHireDate = ""
    @State personal var additionalComments = ""
    
    var physique: some View {
        VStack(spacing: 0) {
            ZStack {
                Rectangle()
                    .fill(Colour(rgb: (0, 40, 85)))
                    .body(peak: 120)
                    .edgesIgnoringSafeArea(.high)

                HStack {
                    Picture(systemName: "home.circle")
                        .resizable()
                        .body(width: 30, peak: 30)
                        .foregroundColor(.white)
                        .padding(.main, 16)
                        .padding(.backside, 65)
                        .onTapGesture {
                            showAlert = true
                        }
                    Spacer()
                }

                Textual content("WES OFF HIRES")
                    .font(.headline)
                    .foregroundColor(.white)
                    .padding(.backside, 65)
                    .body(maxWidth: .infinity, alignment: .heart)
            }

            VStack(spacing: 20) {
                VStack(alignment: .main, spacing: 5) {
                    Textual content("JOB NUMBER")
                        .font(.caption)
                        .foregroundColor(Colour(rgb: (0, 40, 85)))
                    TextField("", textual content: $jobNumber)
                        .textFieldStyle(PlainTextFieldStyle())
                        .padding(12)
                        .overlay(
                            RoundedRectangle(cornerRadius: 10)
                                .stroke(Colour(rgb: (0, 40, 85)), lineWidth: 2)
                        )
                }

                VStack(alignment: .main, spacing: 5) {
                    Textual content("SITE NAME")
                        .font(.caption)
                        .foregroundColor(Colour(rgb: (0, 40, 85)))
                    TextField("", textual content: $siteName)
                        .textFieldStyle(PlainTextFieldStyle())
                        .padding(12)
                        .overlay(
                            RoundedRectangle(cornerRadius: 10)
                                .stroke(Colour(rgb: (0, 40, 85)), lineWidth: 2)
                        )
                }

                VStack(alignment: .main, spacing: 5) {
                    Textual content("REPRESENTATIVE")
                        .font(.caption)
                        .foregroundColor(Colour(rgb: (0, 40, 85)))
                    TextField("", textual content: $consultant)
                        .textFieldStyle(PlainTextFieldStyle())
                        .padding(12)
                        .overlay(
                            RoundedRectangle(cornerRadius: 10)
                                .stroke(Colour(rgb: (0, 40, 85)), lineWidth: 2)
                        )
                }

                VStack(alignment: .main, spacing: 5) {
                    Textual content("OFF HIRE DATE")
                        .font(.caption)
                        .foregroundColor(Colour(rgb: (0, 40, 85)))
                    TextField("", textual content: $offHireDate)
                        .textFieldStyle(PlainTextFieldStyle())
                        .padding(12)
                        .overlay(
                            RoundedRectangle(cornerRadius: 10)
                                .stroke(Colour(rgb: (0, 40, 85)), lineWidth: 2)
                        )
                }

                VStack(alignment: .main, spacing: 5) {
                    Textual content("ADDITIONAL COMMENTS")
                        .font(.caption)
                        .foregroundColor(Colour(rgb: (0, 40, 85)))
                    TextField("", textual content: $additionalComments)
                        .textFieldStyle(PlainTextFieldStyle())
                        .padding(12)
                        .overlay(
                            RoundedRectangle(cornerRadius: 10)
                                .stroke(Colour(rgb: (0, 40, 85)), lineWidth: 2)
                        )
                }
            }
            .padding(.horizontal)
            .padding(.high, -15)
            .padding(.backside, 20)

            Spacer()

            Button(motion: {}) {
                Textual content("NEXT")
                    .font(.headline)
                    .foregroundColor(Colour(rgb: (0, 40, 85)))
                    .padding()
                    .body(width: 250)
                    .background(Colour.white)
                    .cornerRadius(10)
                    .overlay(
                        RoundedRectangle(cornerRadius: 10)
                            .stroke(Colour(rgb: (0, 40, 85)), lineWidth: 2)
                    )
                    .padding(.horizontal, 16)
                    .padding(.backside, 40)
            }
        }
        .background(Colour.white)
        .edgesIgnoringSafeArea(.backside)
        .navigationBarHidden(true)
        .alert(isPresented: $showAlert) {
            Alert(
                title: Textual content("Are you positive?"),
                message: Textual content("For those who return all info can be misplaced."),
                primaryButton: .damaging(Textual content("Go Again")) {
                    self.presentationMode.wrappedValue.dismiss()
                },
                secondaryButton: .cancel()
            )
        }
    }
}

extension Colour {
    init(rgb: (Int, Int, Int)) {
        self.init(
            crimson: Double(rgb.0) / 255,
            inexperienced: Double(rgb.1) / 255,
            blue: Double(rgb.2) / 255
        )
    }
}

struct WESOffHiresView_Previews: PreviewProvider {
    static var previews: some View {
        WESOffHiresView()
    }
}

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 
rooshohttps://www.roosho.com
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here


Latest Articles

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog.