1

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

我有一个 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];
}
4

2 回答 2

6

从 awakeFromNib 调用 addCursorRect: 将不起作用。它必须从resetCursorRects: 的覆盖中调用,它可能会在某个时候被调用并破坏你设置的rect。

于 2011-10-26T13:38:04.443 回答
1

你忘记打电话了[handCursor setOnMouseEntered:YES]。否则,NSCursor将忽略mouseEntered:它发送的事件。

于 2011-09-21T18:14:25.007 回答