小编use*_*195的帖子

iOS14 中的 SwiftUI 键盘回避问题和 IgnoresSafeArea 修饰符问题

iOS13 发现 TextField 没有任何类型的键盘避免处理。因此,我们创建了运行良好的键盘避免机制。我们升级到 iOS14,这导致 TextFields 内置了键盘避免功能。但是,键盘避免功能似乎没有按预期工作。

问题 1 我们遇到的第一个问题是键盘避免在屏幕中心和周围的文本字段中无法正常工作。鉴于此代码:

struct ContentView: View {
    
    @State var text:String = ""
    
    var body: some View {
        
        TextField("Testing", text: $text)

    }
}
Run Code Online (Sandbox Code Playgroud)

在 iPhone 8 Plus 上,文本字段向上移动。我们认为这不应该发生,因为 TextField 不会被键盘隐藏,因此它应该保留在同一位置。

问题 1: 这是一个错误,应该向 Apple 报告吗?我们认为这是一个错误/问题。

我们发现使用以下方法:

struct ContentView: View {
    
    @State var text:String = ""
    
    var body: some View {
        
        VStack {
            Spacer()
            TextField("Testing", text: $text)
        }
        
    }
}
Run Code Online (Sandbox Code Playgroud)

TextField 将移动到键盘正上方。这是预期的行为。我们还发现使用以下代码:

struct ContentView: View {
    
    @State var text:String = ""
    
    var body: some View …
Run Code Online (Sandbox Code Playgroud)

ios swiftui

17
推荐指数
2
解决办法
5181
查看次数

标签 统计

ios ×1

swiftui ×1