首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将列表项向上移动一次会导致动画中断

将列表项向上移动一次会导致动画中断
EN

Stack Overflow用户
提问于 2020-04-03 02:23:51
回答 2查看 88关注 0票数 1

我只是简单地尝试使用一些非常基本的代码来移动列表中的项&除了我试图将项移动到它上面的位置之外,一切都很正常。

看起来好像它首先交换了这两行的数据,然后启动动画从原始位置移动该行。

有没有人知道是什么导致了这个问题,更重要的是,如何修复它?谢谢!

代码语言:javascript
运行
复制
struct ContentView : View {

    @State var zahlen = [1,2,3,4,5]

    var body: some View {
        List {
            ForEach(zahlen, id: \.self) { z in
                Text("\(z)")
            }.onMove(perform: self.move)
        }.environment(\.editMode, .constant(.active))
    }

    func move(source: IndexSet, destination: Int) {
        zahlen.move(fromOffsets: source, toOffset: destination)
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-12-05 20:36:39

对于使用iOS 14.2的我来说,这个bug似乎不再发生了。

票数 0
EN

Stack Overflow用户

发布于 2020-12-05 03:20:21

这是一个迅速的错误,这对我的工作。

代码语言:javascript
运行
复制
 struct ContentView : View {

@State var zahlen = [1,2,3,4,5]

var body: some View {
    List {
        ForEach(zahlen, id: \.self.hashValue) //<<-- here it is "hashValue is deprecated as a Hashable requirement." but until the bug is fixed i think we can use it. 
                                             { z in
            Text("\(z)")
        }.onMove(perform: self.move)
    }.environment(\.editMode, .constant(.active))
}

func move(source: IndexSet, destination: Int) {
    zahlen.move(fromOffsets: source, toOffset: destination)
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60998467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档