您无需手动转换为本地坐标系.您可以通过将convertPoint:fromView:
消息发送到视图来将点转换为本地坐标系.发送nil
作为参数fromView
将从视图的父窗口转换点(无论在哪里).您还可以发送任何其他视图以获取从该空间转换的坐标:
// convert from the window's coordinate system to the local coordinate system NSPoint clickPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil]; // convert from some other view's cooridinate system NSPoint otherPoint = [self convertPoint:somePoint fromView:someSuperview];