使用场景.用户长按某行视图,拖动后插入对应的行.
@State var dataList = ["第一行","第二行","第三行","第四行","第五行"]
var body: some View {
List {
ForEach(dataList, id: \.self) { str in
Text(str)
.onDrag {// 在这里返回 NSItemProvider 对象 实现拖拽功能.
return NSItemProvider(object: NSString(string: str))
}
}
.onMove { from, to in// 这里根据返回的信息调整数据列表
dataList.move(fromOffsets: from, toOffset: to)
}
}
}
标签:dataList,List,NSItemProvider,swiftUI,str,拖拽 From: https://www.cnblogs.com/luobenpaidui/p/16774974.html