How to move or scale WindowGroup by code in visionOS

 
        WindowGroup(id: "Volumetic") {
            GeometryReader3D { geometry in
                VolumeView()
                    .environment(appState)
                    .volumeBaseplateVisibility(.visible) // 是否显示托盘,默认 .visible
                    .scaleEffect(geometry.size.width / initialVolumeSize.width)
                    
            }
            
        }
        .windowStyle(.volumetric)
        .windowResizability(.contentSize)
        .defaultSize(initialVolumeSize)

I can move it through the drag bar that comes with the UI, and change the size by dragging the edge of the plate. I want to use code to achieve the same effect, how to achieve it

Hi @xuhengfei

You can use state to control the view's frame which will cause the volume to resize. Here's code to illustrate the approach.

struct VolumeView: View {
    @State var size = 200.0
    
    var body: some View {
        VStack {
            Button("Bigger") {
                size += 100
            }
            Button("Smaller") {
                size -= 100
            }
        }
        .frame(width: size, height: size).frame(depth: size)
    }
}

Note: this approach allows you to resize the volume programmatically, but prevents the user from resizing it.

How to move or scale WindowGroup by code in visionOS
 
 
Q