Mouse events (NSTrackingArea) on the playground do not work

I have a subclass of NSView that contains the following NSTrackingArea code. But for some reason, mouse events will not be triggered on the playground.

viewWillMoveToWindow is viewWillMoveToWindow , but nothing else fails. Does anyone know what is missing?

 class MyView: NSView { private var trackingArea: NSTrackingArea = NSTrackingArea() // Other stuff omitted here... // ... override func viewWillMoveToWindow(newWindow: NSWindow?) { // Setup a new tracking area when the view is added to the window. trackingArea = NSTrackingArea(rect: self.bounds, options: [.MouseEnteredAndExited, .ActiveAlways], owner: self, userInfo: nil) self.addTrackingArea(trackingArea) } override func updateTrackingAreas() { self.removeTrackingArea(trackingArea) trackingArea = NSTrackingArea(rect: self.bounds, options: [.MouseEnteredAndExited, .ActiveAlways], owner: self, userInfo: nil) self.addTrackingArea(trackingArea) } // Mouse events override func mouseEntered(theEvent: NSEvent) { NSLog("MouseEntered") } override func mouseExited(theEvent: NSEvent) { NSLog("MouseExited") } override func mouseDown(theEvent: NSEvent) { NSLog("MouseDown") } } 
+2
source share
1 answer

According to this 2014 WWDC session:

There are several limitations to Playgrounds. Playgrounds cannot be used for things that require user interaction. Therefore, we have excellent support for displaying live views, but you can only see them, you cannot touch them.

You can find the original video here.

+1
source

Source: https://habr.com/ru/post/971797/


All Articles