问题描述
我有一个 NSWindowController
,其中包含几个 NSViewControllers
。我想通过NSWindowController类普遍接受拖放事件,并且不会被 NSTextView
(包含在 NSViewController
)
I have a NSWindowController
that contains several NSViewControllers
. I would like to universally accept drag and drop events with the NSWindowController class and not be intercepted by other views such as NSTextView
(contained in a NSViewController
)
如何告诉 NSTextView
忽略拖动&
How can I tell NSTextView
to ignore the drag & drop event?
推荐答案
我发现要跳过 NSTextView $,需要做两件事c $ c>的拖放事件的拦截。
I found out that there were two things needed to skip past NSTextView
's interception of the drag and drop event.
在 NSViewController
中,其中包含您的 NSTextView
:
- (void)awakeFromNib
{
[self noDragInView:self.view];
}
- (void)noDragInView:(NSView *)view
{
for (NSView *subview in view.subviews)
{
[subview unregisterDraggedTypes];
if (subview.subviews.count) [self noDragInView:subview];
}
}
现在子类化 NSTextView
并添加此方法:
Now subclass your NSTextView
and add this method:
- (NSArray *)acceptableDragTypes
{
return nil;
}
NSTextView
应该现在可以正确忽略拖放事件,并由NSWindow处理。
The NSTextView
should now properly ignore the drag and drop event and leave it to be handled by the NSWindow.
这篇关于如何禁用NSTextView上的拖放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!