gpt4 book ai didi

swift - 无法启动 NSTrackingArea

转载 作者:可可西里 更新时间:2023-11-01 00:35:49 29 4
gpt4 key购买 nike

我有一个 NSOutlineView,我希望在拖放期间更新 mouseEntered:mouseExited:。所以我尝试向它添加一个 NSTrackingArea。在我的大纲 View 子类中,我有:

let target = self.frame
let options = [NSTrackingAreaOptions.enabledDuringMouseDrag]
let area = NSTrackingArea(rect: target, options: options, owner: self, userInfo: nil)
self.addTrackingArea(area)

但我似乎得到了运行时异常:

[General] trackingArea options 0x400 do not include a type

它一定是非常明显的东西,但所有的谷歌结果似乎都没有表明我做错了什么。如果我这样做:

var trackingID = self.addTrackingRect(target, owner: self, userData: nil, assumeInside: false)

然后鼠标方法确实会触发,但显然只有在释放鼠标按钮时才会触发。

最佳答案

来自documentation :

NSTrackingAreaOptions

The data type defined for the constants specified in the options parameter of init(rect:options:owner:userInfo:). These constants are described below; you can specify multiple constants by performing a bitwise-OR operation with them. In particular, you must supply one or more of the tracking-type constants (that is, mouseEnteredAndExited, mouseMoved, and cursorUpdate) and one of the active constants (that is, activeWhenFirstResponder, activeInKeyWindow, activeInActiveApp, and activeAlways). In addition, you may specify any of the behavior constants (that is, assumeInside, inVisibleRect, and enabledDuringMouseDrag).

这意味着需要一个或多个 type 常量和一个 active 常量。

关于swift - 无法启动 NSTrackingArea,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42770693/

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