SwiftUI ScaleEffect image with center of mousepointer

Viewed 115

I like to scale an image on macOS with a pinch - gesture, which works well. But the image is scaled always (and expectingly) centers.

What I need is that an Image is scaled with an anchor on the mousepointer. But I have no clue how to read the current mousePointer position. What I have so far is:

                GeometryReader { geo in
                ScrollView([.horizontal, .vertical], showsIndicators: true) {
                    
                    Image(nsImage: image!)
                        .resizable()
                        .scaledToFill()
                        .animation(.default)
                        **// Here the 'anchor' should have a pointer position **                         
                        .scaleEffect(setZoom(magnificationLevel: magnificationState.scale), anchor: UnitPoint.center)
                        .frame(width: geo.size.width, height: geo.size.height)
                        .onAppear() {
                            self.imageMagnificationState = CGFloat(1.0)
                        }
                     
                }
            }

Is there any snippet for this every day task? How to get the cursor position? SwiftUI doc is very lame here.

0 Answers
Related