In my application I want to dynamically create windows (NSWindows) and have a special window (which is a NSWindow too and I call dump space) where I can drag the other windows for closing them.
在我的应用程序中,我想动态创建窗口(NSWindows)并有一个特殊窗口(也是NSWindow,我调用转储空间),我可以拖动其他窗口关闭它们。
Basically the dump space should detect when I "drop" a window there so it can trigger the action to release and close the window.
基本上,转储空间应该检测我何时“放下”窗口,以便它可以触发释放和关闭窗口的操作。
Is there something on the Cocoa drag and drop model that I could use? If not I'd like to know some workaround that I could do in order to simulate those actions.
在我可以使用的Cocoa拖放模型上有什么东西吗?如果不是,我想知道我可以做的一些解决方法,以模拟这些行为。
1 个解决方案
#1
1
In your dump space class implement the NSDraggingDestination protocol which has several messages to handle drag operations. In performDragOperation: you can handle your window. I recommend to implement NSDraggingSource in the class that starts dragging a window on mouseDown:
or mouseMoved:
. This way you can define your own pasteboard datatype for dragging windows. This can then be used in the dump space to see what was actually dropped on it and trigger your window processing. There's a relatively complicated example for all the required in this example.
在您的转储空间类中实现NSDraggingDestination协议,该协议有几条消息来处理拖动操作。在performDragOperation中:您可以处理您的窗口。我建议在开始拖动mouseDown:或mouseMoved:上的窗口的类中实现NSDraggingSource。这样,您可以定义自己的用于拖动窗口的粘贴板数据类型。然后可以在转储空间中使用它来查看实际丢弃的内容并触发窗口处理。对于此示例中的所有要求,有一个相对复杂的示例。
#1
1
In your dump space class implement the NSDraggingDestination protocol which has several messages to handle drag operations. In performDragOperation: you can handle your window. I recommend to implement NSDraggingSource in the class that starts dragging a window on mouseDown:
or mouseMoved:
. This way you can define your own pasteboard datatype for dragging windows. This can then be used in the dump space to see what was actually dropped on it and trigger your window processing. There's a relatively complicated example for all the required in this example.
在您的转储空间类中实现NSDraggingDestination协议,该协议有几条消息来处理拖动操作。在performDragOperation中:您可以处理您的窗口。我建议在开始拖动mouseDown:或mouseMoved:上的窗口的类中实现NSDraggingSource。这样,您可以定义自己的用于拖动窗口的粘贴板数据类型。然后可以在转储空间中使用它来查看实际丢弃的内容并触发窗口处理。对于此示例中的所有要求,有一个相对复杂的示例。