微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SwiftUI 中的 Spring 动画,IOS14 已损坏

如何解决SwiftUI 中的 Spring 动画,IOS14 已损坏

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())
        }
    }
}

Video example

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。