iOS SwiftUI 键盘推动使文本折叠

问题描述 投票:0回答:1

我们可以简单地将文本字段上方的所有内容推到顶部而不折叠文本行吗?

enter image description hereenter image description here

这是我的身体代码。

var body: some View {
        ZStack(alignment: .top) {
            VStack(spacing: 24) {
                if DeviceUtil.getDeviceType() != .smallPhone {
                    Image(systemName: "sun.min.fill")
                        .resizable()
                        .scaledToFit()
                        .frame(width: 220, height: 46)
                    Image(systemName: "building.2")
                        .resizable()
                        .scaledToFit()
                        .frame(width: DeviceUtil.getDeviceType() == .iPad ? 350 : 200, height: DeviceUtil.getDeviceType() == .iPad ? 240 : 150)
                        .padding(.top, 24)
                } else {
                    Image("bLogo")
                        .resizable()
                        .scaledToFit()
                        .frame(width: 100, height: 34)
                    
                    Image("companyIntro")
                        .resizable()
                        .scaledToFit()
                        .frame(width: 100, height: 140)
                        .padding(.top, 12)
                }
                
                Text("One place\nfor all your work.")
                    .font(.titilliumWebRegular(size: DeviceUtil.getDeviceType() == .smallPhone ? 16 :  24))
                    .multilineTextAlignment(.center)
                
                Text("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi.")
                    .font(.titilliumWebRegular(size: 15))
                    .multilineTextAlignment(.center)
                
                HStack {
                    Rectangle()
                        .frame(height: 1)
                        .foregroundColor(.black)
                }
                .background(Color.gray.opacity(0.1))
                .padding(.horizontal, DeviceUtil.getDeviceType() == .normalPhone ? 64 : 34)
                mainContent
                Spacer()
            }
            .padding()
        }
        .background {
            Image("companyLaunch")
                .resizable()
                .scaledToFill()
                .ignoresSafeArea()
        }
    }
ios swiftui keyboard
1个回答
0
投票

您可以将视图包裹在

ScrollView
中,以便您的内容得到推送:

ScrollView {
    ZStack(alignment: .top) {
        ...
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.