相关疑难解决方法(0)

已发布作品适用于单个对象,但不适用于对象数组

我正在尝试制作可单独移动的对象。我能够为一个对象成功完成此操作,但是一旦将其放入数组中,这些对象将无法再移动。

模型:

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)

xcode swiftui xcode11 combine

2
推荐指数
2
解决办法
603
查看次数

标签 统计

combine ×1

swiftui ×1

xcode ×1

xcode11 ×1