3

In OS X, the mouse cursor typically disappears when you are typing in a text field, in every app. Even when I am typing in this text field here on Stack Overflow, the cursor disappears. This makes sense most of the time. But in my app I want it to stay visible, because the user has to do a lot of clicking between text fields, and it is really nasty when the mouse is always gone.

How can I make the cursor stay visible when typing in an NSTextField?

4

2 回答 2

3

好的,我解决了。

当您在此处添加断点时,+[NSCursor setHiddenUntilMouseMoves:]您会注意到,Apple 调用[NSTextField keyDown:]
它时,为了防止鼠标消失,重写此方法不是一个好主意。-(void)controlTextDidChange:(NSNotification *)obj所以我使用 NSTextFieldDelegate 在和上获得通知-(void)controlTextDidEndEditing:(NSNotification *)obj。然后我打电话[NSCursor setHiddenUntilMouseMoves:NO]

它不是 100% 干净,但它可以工作。

非常感谢 Richard 和 Kurt 的大力帮助 :)

于 2013-01-23T14:04:36.220 回答
2

我的猜测是,在苹果代码中很深,鼠标在打字时会消失。因为即使您刚开始打字,鼠标也会消失,甚至出现在文本框之外。就像您在浏览器窗口中单击并键入一样。

于 2013-01-22T04:26:36.670 回答