如何禁用NSTextView上的拖放? [英] How do I disable drag and drop on NSTextView?

查看:122
本文介绍了如何禁用NSTextView上的拖放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 的拖放事件的拦截。

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上的拖放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆