SwiftUI iOS14 - 禁用键盘回避 [英] SwiftUI iOS14 - Disable keyboard avoidance

查看:22
本文介绍了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 - 禁用键盘回避的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆