我正在尝试制作可单独移动的对象。我能够为一个对象成功完成此操作,但是一旦将其放入数组中,这些对象将无法再移动。
模型:
class SocialStore: ObservableObject {
@Published var socials : [Social]
init(socials: [Social]){
self.socials = socials
}
}
class Social : ObservableObject{
var id: Int
var imageName: String
var companyName: String
@Published var pos: CGPoint
init(id: Int, imageName: String, companyName: String, pos: CGPoint) {
self.id = id
self.imageName = imageName
self.companyName = companyName
self.pos = pos
}
var dragGesture : some Gesture {
DragGesture()
.onChanged { value in
self.pos = value.location
print(self.pos)
}
}
}
Run Code Online (Sandbox Code Playgroud)
多张图片(不跟随拖动的图片):
struct ContentView : View …Run Code Online (Sandbox Code Playgroud)