我在draggingUpdated:
子类中覆盖WebView
。这样,我就可以获得当前拖动目标为NSPoint
[(id<NSDraggingInfo>)sender draggingLocation]
我希望获得此NSPoint
并将其“转换”为坐标 WebView
,然后使用WebView
获取该点的基础元素是elementAtPoint:
问题是,我得到了NSPoint
,而且我还有WebView的边界/框架。这怎么可兑换?
答案 0 :(得分:6)
对此使用-convertPointFromBase:
是不正确的。不推荐使用该方法,并且建议的替换(-convertPointFromBacking:
)不适用于此目的,因为它假定输入点位于后备存储坐标系中。 (这实际上暗示了-convertPointFromBase:
的最初目的,这是现在被抛弃的Leopard时代高分辨率支持尝试的一部分。它所转换的“基本坐标系”应该是像素对齐。搜索'像素对齐并将视图坐标转换为Leopard AppKit release notes中的“基础”空间。)
您需要-convertPoint:fromView:
,并且应该nil
传递fromView
参数。请参阅Cocoa Drawing Guide: Coordinate Systems and Transforms – Converting from Window to View Coordinates。
答案 1 :(得分:0)
[self convertPointFromBase:point];
是的,这就是全部。