如何使用 NSDraggingInfo 或类似方法检测拖动操作是否被取消?

发布于 2024-09-09 04:20:26 字数 172 浏览 2 评论 0原文

我创建了 NSImageView 的子类,并实现了在同一类的其他实例之间拖动图像的非正式协议。我在拖动操作之前保留对视图图像的引用,并且能够在给定某些条件的情况下将其设置回所述图像。

但是,我似乎无法检测拖动操作是否被取消。我知道 DraggingEnded 方法被调用,但当拖动成功时它也会被调用。有什么想法吗?

I've created a subclass of NSImageView and implemented the informal protocol for dragging images between other instances of the same class. I am keeping a reference to the image of the view prior to the dragging operation and am able to set it back to said image given certain criteria.

However, I can't seem to detect if the dragging operation was cancelled. I know that the draggingEnded method is called but it is also called when a drag was successful. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经暖 2024-09-16 04:20:26

我遇到了类似的需求。事实上,您可以检查传递给 NSDraggingSource 协议方法 draggedImage:endAt:operation:operation 参数来检测拖动取消,这一事实并没有很好的记录。

draggedImage:endAt:operation: 方法中只需添加以下检查:

if (operation == NSDragOperationNone)
    return;

// Otherwise perform any drag completion tasks.

I encountered a similar requirement. The fact that you can examine the operation argument passed to the NSDraggingSource protocol method draggedImage:endedAt:operation: to detect drag cancellation is not very well documented.

In the draggedImage:endedAt:operation: method just add the following check:

if (operation == NSDragOperationNone)
    return;

// Otherwise perform any drag completion tasks.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文