Skip to content

Instantly share code, notes, and snippets.

@rampatra
Created August 14, 2022 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rampatra/948787c6ff43e957eed7afb76bc0a31a to your computer and use it in GitHub Desktop.
Save rampatra/948787c6ff43e957eed7afb76bc0a31a to your computer and use it in GitHub Desktop.
private func selectDrawing(at point: NSPoint) {
print("hit test \(view.layer!.hitTest(point)) \n \(view.layer!.hitTest(point)?.className)")
print("============================")
print("hit test \(view.layer!.hitTest(view.convert(point, from: nil))) \n \(view.layer!.hitTest(view.convert(point, from: nil))?.className)")
print("============================")
print("hit test \(view.layer!.hitTest(view.layer!.convert(point, from: nil))) \n \(view.layer!.hitTest(view.layer!.convert(point, from: nil))?.className)")
print("============================")
print("hit test \(view.layer!.hitTest(view.convert(point, to: nil))) \n \(view.layer!.hitTest(view.convert(point, to: nil))?.className)")
print("============================")
print("hit test \(view.layer!.hitTest(view.layer!.convert(point, to: nil))) \n \(view.layer!.hitTest(view.layer!.convert(point, to: nil))?.className)")
}
@rampatra
Copy link
Author

Output:

hit test Optional(<_NSViewBackingLayer:0x600001848510; name = "NSView"; position = CGPoint (0 0); bounds = CGRect (0 0; 1680 1025); delegate = <NSView: 0x7ff0d4125b00>; sublayers = (<CAShapeLayer: 0x60000168a940>, <_NSViewBackingLayer: 0x600001872370>, <CALayer: 0x60000168b340>); needsLayoutOnGeometryChange = NO; masksToBounds = YES; hitTestsContentsAlphaChannel = YES; allowsGroupBlending = NO; anchorPoint = CGPoint (0 0); contentsScale = 2; NS_view = <NSView: 0x7ff0d4125b00>; name = NSView>) 
 Optional("_NSViewBackingLayer")
============================
hit test Optional(<_NSViewBackingLayer:0x600001848510; name = "NSView"; position = CGPoint (0 0); bounds = CGRect (0 0; 1680 1025); delegate = <NSView: 0x7ff0d4125b00>; sublayers = (<CAShapeLayer: 0x60000168a940>, <_NSViewBackingLayer: 0x600001872370>, <CALayer: 0x60000168b340>); needsLayoutOnGeometryChange = NO; masksToBounds = YES; hitTestsContentsAlphaChannel = YES; allowsGroupBlending = NO; anchorPoint = CGPoint (0 0); contentsScale = 2; NS_view = <NSView: 0x7ff0d4125b00>; name = NSView>) 
 Optional("_NSViewBackingLayer")
============================
hit test Optional(<_NSViewBackingLayer:0x600001848510; name = "NSView"; position = CGPoint (0 0); bounds = CGRect (0 0; 1680 1025); delegate = <NSView: 0x7ff0d4125b00>; sublayers = (<CAShapeLayer: 0x60000168a940>, <_NSViewBackingLayer: 0x600001872370>, <CALayer: 0x60000168b340>); needsLayoutOnGeometryChange = NO; masksToBounds = YES; hitTestsContentsAlphaChannel = YES; allowsGroupBlending = NO; anchorPoint = CGPoint (0 0); contentsScale = 2; NS_view = <NSView: 0x7ff0d4125b00>; name = NSView>) 
 Optional("_NSViewBackingLayer")
============================
hit test Optional(<_NSViewBackingLayer:0x600001848510; name = "NSView"; position = CGPoint (0 0); bounds = CGRect (0 0; 1680 1025); delegate = <NSView: 0x7ff0d4125b00>; sublayers = (<CAShapeLayer: 0x60000168a940>, <_NSViewBackingLayer: 0x600001872370>, <CALayer: 0x60000168b340>); needsLayoutOnGeometryChange = NO; masksToBounds = YES; hitTestsContentsAlphaChannel = YES; allowsGroupBlending = NO; anchorPoint = CGPoint (0 0); contentsScale = 2; NS_view = <NSView: 0x7ff0d4125b00>; name = NSView>) 
 Optional("_NSViewBackingLayer")
============================
hit test Optional(<_NSViewBackingLayer:0x600001848510; name = "NSView"; position = CGPoint (0 0); bounds = CGRect (0 0; 1680 1025); delegate = <NSView: 0x7ff0d4125b00>; sublayers = (<CAShapeLayer: 0x60000168a940>, <_NSViewBackingLayer: 0x600001872370>, <CALayer: 0x60000168b340>); needsLayoutOnGeometryChange = NO; masksToBounds = YES; hitTestsContentsAlphaChannel = YES; allowsGroupBlending = NO; anchorPoint = CGPoint (0 0); contentsScale = 2; NS_view = <NSView: 0x7ff0d4125b00>; name = NSView>) 
 Optional("_NSViewBackingLayer")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment