我已经构建了一个自定义窗口;在这个窗口中,我显示了nsbutton。如果单击按钮,我将显示上下文菜单。问题是,我不想关闭我的窗口,但不知何故,当我从nsmenu中选择选项时,鼠标退出事件就会被触发。
我想要防止这种影响。我想不出来。
任何帮助都将不胜感激。提前感谢
-(void)rightMouseDown:(NSEvent *)theEvent
{
NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@"Contextual Menu"];
[[theMenu addItemWithTitle:@"Remove From List" action:@selector(removeWithIdentifier) keyEquivalent:@""] setTarget:self];
[[theMenu addItemWithTitle:@"Open" action:@selector(openAppWithIdentifier) keyEquivalent:@""] setTarget:self];
[theMenu popUpMenuPositioningItem:nil atLocation:NSMakePoint(self.bounds.size.width-20, self.bounds.size.height-10) inView:self];
}
-(void)removeWithIdentifier
{
//My custom view is getting mouse exited event from here
//I want prevent it.
}发布于 2017-05-18 18:26:15
朋友们,我已经找到答案了。
我发现如果你的窗口级别是"NSPopUpMenuWindowLevel“,并且它的视图在它上面实现了任何上下文菜单,那么这个视图总是会得到鼠标退出的事件。
将其发布以供将来参考。
谢谢。
https://stackoverflow.com/questions/42113698
复制相似问题