1
struct ContentView: View {
    @State var search: String = ""
    let data = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"]
    
    var body: some View {
        VStack {
            TextField("search", text: self.$search)
                .foregroundColor(.primary)
                .padding(EdgeInsets(top: 8, leading: 6, bottom: 8, trailing: 6))
                .background(Color(.secondarySystemBackground))
                .cornerRadius(10.0)
                .padding(.horizontal)
            
            List(data.filter { $0.contains(self.search.lowercased()) || self.search.isEmpty }, id:\.self) { str in
                HStack {
                    Text(str)
                        .font(.title)
                        .padding(.leading)
                    
                    Spacer()
                }
                .frame(height: 45)
            }
            .animation(.spring())
            .listStyle(GroupedListStyle())
        }
    }
}

视频示例

当我快速编辑搜索文本时,列表无法正常工作。此错误仅在带有 .animation(.spring()) 修饰符的 IOS 14+ 中发生。

4

0 回答 0