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.
我有一个NSView的子类,它包含以下的NSTrackingArea代码。但是出于某种原因,鼠标事件不会在操场上触发。
The viewWillMoveToWindow
is being called, but nothing else seems to fire. Does anyone have a clue to what is missing?
这个viewwillmovetowindowdowis being called, but anything else seem to fire。有人知道少了什么吗?
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 个解决方案
#1
1
According to this 2014 WWDC session:
根据2014年全球开发者大会:
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
你可以在这里找到原始视频
#1
1
According to this 2014 WWDC session:
根据2014年全球开发者大会:
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
你可以在这里找到原始视频