1

我有一个基本的 Cocoa 应用程序,其中包含一个NSTextField模拟超链接的自定义项。

我使用以下代码在文本字段实现中设置自定义光标:

- (void) resetCursorRects {
    [self addCursorRect: self.bounds cursor: [NSCursor pointingHandCursor]];
}

mouseUp:单击标签时,我还覆盖并执行了操作。就我而言,我通过NSWorkspace.

问题:当浏览器打开时,“指向手”光标被重置为普通箭头光标(因为最上面的窗口现在是 Safari)。但是,当我返回我的应用程序并将光标移到我的自定义超链接标签上方时,光标不会变为“指向手”。

只有在我调整窗口大小(并且光标矩形被重置)之后,光标才会再次工作。

我尝试在mouseUp:调用中使光标 rect 无效,但这没有用。

4

1 回答 1

0

Please add a line of reset before adding cursor rect although it is not recommended on direct call by the document. Or you may ask the window to do it.

[self resetCursorRects];
...
[fatherWindow invalidateCursorRectsForView:self];
...
[self addCursorRect:[self bounds] cursor:[NSCursor pointingHandCursor]];

The follow code is used on one of our apps and it works very well:

- (void) resetCursorRects
{
    [super resetCursorRects];
    [self addCursorRect: [self bounds] cursor: [NSCursor     openHandCursor]];
}
于 2015-04-20T21:11:32.967 回答