就像在 Interface Builder 中一样在窗口之间绘制线条
我有两个窗口,每个窗口都有一个圆形 NSView:
------------------ ------------
|X-+ Oscillator | |X-+ Mixer |
|----------------| |----------|
| | | |
| O | | O |
| | | |
| | | |
------------------ ------------
两个窗口都位于单独的 NIB 中。我希望能够在运行时使用拖放操作在两个圆形 NSView 之间画一条线,就像在 Interface Builder 中连接 IBOutlet 一样:
------------------ ------------
|X-+ Oscillator | |X-+ Mixer |
|----------------| |----------|
| | | |
| O-------+-----+-----O |
| | | |
| | | |
------------------ ------------
我还希望能够确定哪个NSView
使用绘制的线连接 NSView
。我需要它来将振荡器连接到混频器。我还希望能够通过拖动到空白区域来删除连接。
谁能解释我该怎么做?谢谢。
I have two windows, each with a round NSView
:
------------------ ------------
|X-+ Oscillator | |X-+ Mixer |
|----------------| |----------|
| | | |
| O | | O |
| | | |
| | | |
------------------ ------------
Both windows are in a seperate NIB. I want to be able to draw a line between the two round NSView
s at runtime, using drag'n'drop, just like connecting IBOutlets in Interface Builder:
------------------ ------------
|X-+ Oscillator | |X-+ Mixer |
|----------------| |----------|
| | | |
| O-------+-----+-----O |
| | | |
| | | |
------------------ ------------
I also want to be able to determine to which NSView
s the NSView
s are connected using the drawn lines. I need this to connect Oscillators to Mixers. I also want to be able to remove the connections by dragging into empty space.
Can anyone explain me how to do this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是有一个可以在其中绘制的视图,该视图跨越两个窗口的组合矩形(或它们所在的一个或多个屏幕)。这通常是通过无边框、透明的“覆盖窗口”来完成的。网上有很多无边框透明窗口的示例。
拖动开始时,覆盖窗口会出现(但用户不可见)位于绘图区域上方。当拖动更新时,您可以绘制线条,将覆盖视图坐标转换为源/目标视图坐标或从源/目标视图坐标转换过来。拖动完成后,执行一些动画(例如淡入淡出或闪烁),然后排序覆盖窗口。
The problem is having a view into which you can draw that spans the two windows' combined rects (or the screen or screens they're on). This is typically done with a borderless, transparent "overlay window." There are lots of examples of a borderless, transparent window available online.
On the start of the drag, the overlay window appears (but is invisible to the user) positioned over your drawing area. As the drag is updated, you draw your line, translating the overlay view coordinates to/from the source/target view coordinates. When the drag is complete, do some animation (like a fade or a blink) then order out the overlay window.
我认为您的方法的最大问题是您有两个独立的窗口,一个带有振荡器视图,另一个带有混频器视图。如果您可以更改设计以便在单个窗口中显示所有合成器组件(或者可能是射频组件 - 不确定您在做什么!),那么您的问题将变得简单得多。
正如约书亚所说,一种方法是使用仅显示链接的不可见覆盖窗口。但是,如果您确实使用两个单独的窗口,那么您不能(正如 Joshua 所建议的那样)在拖动结束时排序覆盖窗口。如果这样做,链接将在拖动结束时消失。如果您希望继续显示链接(考虑 Interface Builder 或更好的是 Quartz Composer),那么您需要某种机制来持久显示链接。如果您希望稍后允许用户删除该链接,则尤其如此。
我强烈建议围绕单个窗口构建界面。另外,请考虑使用核心动画将每个链接显示为图层。
戴夫
I think the biggest problem with your approach is the fact that you have two separate windows, one with the oscillator view, and one with the mixer. If you could change your design so as to display all synthesizer components (or maybe radio frequency components - not sure what you're doing!) in a single window, then your problems will get much simpler.
As Joshua said, one approach is to use an invisible overlay window which just shows the link. But if you're really using two separate windows then you can't (as Joshua suggests) order out the overlay window at the end of the drag. If you do that, the link will disappear at the end of the drag. If you want the link to continue to be displayed (think of Interface Builder or - better yet - Quartz Composer) then you need some mechanism to persistently display the link. This is especially true if you want to, at a later point, allow the user to remove the link.
I'd strongly suggest building your interface around a single window. Also, consider using Core Animation to display each link as a layer.
Dave