NSPanGestureRecognizer.LocationInView not accounting for Transform

Hi,

I'm trying to get the position of a gesture relatively to a NSView, so I'm using the NSPanGestureRecognizer.LocationInView. It works until I set the Layer.AffineTransform matrix of the view. When doing this the returned position is the same as if I hadn't set anything. It looks the LocationInView wouldn't account for the Transform. The same thing works differently in iOS, so I'm wondering whether this is a bug in macOS, or the os's are different, or it's my mistake?

Regards,

Alvaro.

Can you show the code (probably in .changed part of the gesture)


Could this help www.informit.com/articles/article.aspx?p=2185202&seqNum=3

What kind of view is it? Have you checked whether the layer is non-nil? On macOS, a view can be layer-backed, or not layer-backed (the default), or (rarely) layer-hosting.


In general, though, the locationInView returns the location in the coordinate system of the view, i.e. its bounds coordinate system. This is unaffected by any transform applied to the view (which affects the frame coordinate system), and semantically I would expect it to be unaffected by a transform applied to the view's layer.

The link article is for iOS. I tried to do the same for mac, but there are no UIView.Center and UIView.Translate properties on NSView, are they?


I'm translating a NSView using the layer's affine transofrm.

myView.wantsLayer = true

myView.layer?.transform = // The transformation

Maybe the problem I'm having is not related to the loactionInView, but the way I'm translating a view. In IOS, I set myView.transform and that affects the "frame" coordinate system of the view, but in macOS there is no transform in view, so I'm setting myView.layer.transform, and this seems to be ignored by the "frame" coordinate system, despite it works to translate the object. Is there any way to set a translation so the frame is also altered accordingly?

Instead of center, you can use (midX, midY).


You should probably use:

func translateOrigin(to translation: NSPoint)
NSPanGestureRecognizer.LocationInView not accounting for Transform
 
 
Q