How Can I Show NSMenu at Mouse Cursor?

不想你离开。 提交于 2019-12-03 17:00:28

You are mixing Quartz with Cocoa. There is a lot of overlap between the APIs, and if you can stick with just one, do so. Do this instead:

NSPoint point = [NSEvent mouseLocation];

Quartz and Cocoa use different coordinate systems: Quartz uses "hardware address" style coordinates with (0, 0) at the top left, Cocoa uses "mathematics" style coordinates with (0, 0) at the bottom left.

Łukasz

Define in init:

NSPoint lastClick;

and then:

- (void) rightMouseDown:(NSEvent *)theEvent {
    lastClick = [self convertPoint: theEvent.locationInWindow fromView: nil];
    [super rightMouseDown:theEvent];
}

and in your action use it

- (IBAction)someAction:(id)sender {
    //Use lastCLick.x and lastClick.y
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!