问题
I have a a subclass of NSView which contains the following NSTrackingArea code. But for some reason the mouse events won't trigger in Playground.
The viewWillMoveToWindow
is being called, but nothing else seems to fire. Does anyone have a clue to 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")
}
}
回答1:
According to this 2014 WWDC session:
There are few more limitations with Playgrounds. Playgrounds cannot be used for things which require user interaction. So we have great support for showing live views but you can only see them, you can't touch them.
You can find the original video here
来源:https://stackoverflow.com/questions/34442116/mouse-events-nstrackingarea-in-playground-not-working