我有一个弹出窗口的一部分,我用线条绘制了一个自定义光标。因此,我不希望标准光标显示在某个区域(isInDiagram)内。
这是我的代码:
- (void)mouseMoved:(NSEvent *)theEvent {
position = [self convertPoint:[theEvent locationInWindow] fromView:nil];
if(![self isInDiagram:position]) {
[NSCursor unhide];
}
else{
[NSCursor hide];
}
[self setNeedsDisplay: YES];
}
- (bool) isInDiagram: (NSPoint) p {
return (p.x >= bborder.x + inset) && (p.y >= bborder.y + inset) &&
(p.x <= self.window.frame.size.width - bborder.x - inset) &&
(p.y <= self.window.frame.size.height - bborder.y - inset);
}
现在隐藏光标工作得很好,但取消隐藏总是滞后。我无法弄清楚最终触发光标再次显示的原因。但是,如果我循环取消隐藏命令取消隐藏工作:
for (int i = 0; i<100; i++) {
[NSCursor unhide];
}
有什么想法可以在不使用这个丑陋的循环的情况下解决这个问题吗?