更改特定视图的 NSCursor

发布于 2024-12-06 02:19:29 字数 563 浏览 2 评论 0原文

我试图在光标经过视图时更改光标,但我想我没有正确编码它,因为它不起作用。

我有一个 appcontroller 类,在它的 .m 文件中我有这个

- (void) awakeFromNib { 

      //set up the cursors
      NSCursor * handCursor = [NSCursor closedHandCursor];

      //make a box
      Box* newBox = [[Box alloc] initWithFrame:NSMakeRect(10.0, 10.0, 100.0, 100.0)];
      //set up the rect for the cursor change
      NSRect rectForCursor = [newBox frame];
      [newBox addCursorRect:rectForCursor cursor:handCursor];
      //add box to main win
      [[mainWin contentView] addSubview:newBox];
}

I'm trying to change the cursor when it passes over a view but I guess I am not coding it correctly as it is not working.

I have an appcontroller class and in it's .m file I have this

- (void) awakeFromNib { 

      //set up the cursors
      NSCursor * handCursor = [NSCursor closedHandCursor];

      //make a box
      Box* newBox = [[Box alloc] initWithFrame:NSMakeRect(10.0, 10.0, 100.0, 100.0)];
      //set up the rect for the cursor change
      NSRect rectForCursor = [newBox frame];
      [newBox addCursorRect:rectForCursor cursor:handCursor];
      //add box to main win
      [[mainWin contentView] addSubview:newBox];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迎风吟唱 2024-12-13 02:19:30

从 awakeFromNib 中调用 addCursorRect: 不起作用。它必须从resetCursorRects:的重写中调用,这可能会在某个时刻被调用并破坏您设置的矩形。

Calling addCursorRect: from within awakeFromNib won't work. It must be called from within an override of resetCursorRects:, which is probably getting invoked at some point and clobbering the rect your set up.

感情洁癖 2024-12-13 02:19:30

您忘记调用[handCursor setOnMouseEntered:YES]。否则,NSCursor 将忽略它发送的 mouseEntered: 事件。

You've forgotten to call [handCursor setOnMouseEntered:YES]. Otherwise, NSCursor will ignore the mouseEntered: event it is sent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文