在视图协调系统中获取[NSEvent mouseLocation] >>

问题描述 投票:13回答:2

我有一个正在捕获mouseDown事件的NSView。

我正在使用以下命令来协调鼠标单击:

- (void)mouseDown:(NSEvent *)theEvent {
    NSPoint touchPoint = [NSEvent mouseLocation];
    //Rest of code
}

但是,这会将clickPoint设置为鼠标在全局屏幕协调中的位置。

我想获得单击在相对视图坐标中的位置-如果用户单击窗口的左下角,则无论包含窗口在窗口的哪个位置,我都希望该点为(0,0)屏幕。

我有一个正在捕获mouseDown事件的NSView。我正在使用以下命令来协调鼠标单击:-(void)mouseDown:(NSEvent *)theEvent {NSPoint touchPoint = [NSEvent mouseLocation]; ...

macos mousedown nsevent
2个回答
25
投票

您应该使用locationInWindow,而不是mouseLocationlocationInWindow上的文档显示了如何从那里开始:


0
投票

Swift

© www.soinside.com 2019 - 2024. All rights reserved.