gpt4 book ai didi

xcode - Playground 中的鼠标事件 (NSTrackingArea) 不起作用

转载 作者:可可西里 更新时间:2023-11-01 02:18:16 26 4
gpt4 key购买 nike

我有一个 NSView 的子类,其中包含以下 NSTrackingArea 代码。但出于某种原因,鼠标事件不会在 Playground 中触发。

正在调用 viewWillMoveToWindow,但似乎没有其他任何东西触发。有没有人知道缺少什么?

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")
}
}

最佳答案

根据 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.

可以找到原视频here

关于xcode - Playground 中的鼠标事件 (NSTrackingArea) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34442116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com