小编Igo*_*nko的帖子

iOS16 Bug 键盘在关闭 SwiftUI 时破坏了布局

在 iOS16 中,工作表内部存在键盘的错误,当工作表关闭时键盘消失(没关系),但布局未更新。我只看到了关于同一问题的 1 个问题,想知道也许有人找到了临时解决方法,直到苹果不解决这个问题。重现代码:

struct Test: View {
    
    @State var isPresented: Bool = false
    @State var text: String = ""
    
    var body: some View {
        VStack{
            Button {
                isPresented.toggle()
            } label: {
                Text("PRESENT")
            }
        }
        .sheet(isPresented: $isPresented) {
            ZStack {
                Color.red
                VStack{
                    TextField("Test", text: $text)
                        .frame(height: 50, alignment: .center)
                    Spacer()
                    Rectangle()
                        .fill(Color.blue)
                        .frame(width:300, height: 50)
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

视频: https: //vimeo.com/758845068

swift swiftui ios16

11
推荐指数
1
解决办法
1657
查看次数

标签 统计

ios16 ×1

swift ×1

swiftui ×1