【问题标题】:Changing NSCursor for a specific view更改特定视图的 NSCursor
【发布时间】:2011-09-21 16:33:39
【问题描述】:

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

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

【问题讨论】:

    标签: objective-c nscursor


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-24
        • 1970-01-01
        • 1970-01-01
        • 2016-02-23
        • 1970-01-01
        • 2013-04-04
        相关资源
        最近更新 更多