本文介绍了SwiftUI iOS14-禁用键盘避免的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在iOS14上禁用本机键盘避免功能?

Is there a way to disable the native keyboard avoidance on iOS14?

iOS13中没有键盘避免功能,因此我想实现自己的键盘功能,但是当我在iOS14上执行本机功能时,仍处于活动状态,因此我的实现和本机功能同时运行,而我却没有这样做不想.

There is no keyboard avoidance in iOS13, so I want to implement my own, but when I do the native one on iOS14 is still active, so both my implementation and the native one run at the same time, which I don't want.

我的部署目标是iOS13,因此我需要同时针对iOS13 iOS14的解决方案.

My deployment target is iOS13, so I need a solution for both iOS13 and iOS14.

推荐答案

如果要改编iOS 14代码以便在iOS上编译,则可以使用 if #available(iOS 14.0,*)13.

You can use if #available(iOS 14.0, *) if you want to adapt the iOS 14 code so it compiles on iOS 13.

此处是此答案的改编版本,可在iOS 13和iOS 14上使用:

Here is an adapted version of this answer to work on both iOS 13 and iOS 14:

struct ContentView: View {
    @State var text: String = ""

    var body: some View {
        if #available(iOS 14.0, *) {
            VStack {
                content
            }
            .ignoresSafeArea(.keyboard, edges: .bottom)
        } else {
            VStack {
                content
            }
        }
    }

    @ViewBuilder
    var content: some View {
        Spacer()
        TextField("asd", text: self.$text)
            .textFieldStyle(RoundedBorderTextFieldStyle())
        Spacer()
    }
}

这篇关于SwiftUI iOS14-禁用键盘避免的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 12:15