如何使用 NSDraggingInfo 或类似方法检测拖动操作是否被取消?
我创建了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的需求。事实上,您可以检查传递给 NSDraggingSource 协议方法
draggedImage:endAt:operation:
的operation
参数来检测拖动取消,这一事实并没有很好的记录。在
draggedImage:endAt:operation:
方法中只需添加以下检查:I encountered a similar requirement. The fact that you can examine the
operation
argument passed to the NSDraggingSource protocol methoddraggedImage:endedAt:operation:
to detect drag cancellation is not very well documented.In the
draggedImage:endedAt:operation:
method just add the following check: