Objective c 更改特定视图的NSCursor
我试图在光标经过视图时更改光标,但我想我没有正确编码,因为它不工作 我有一个appcontroller类,在它的.m文件中有这个Objective c 更改特定视图的NSCursor,objective-c,nscursor,Objective C,Nscursor,我试图在光标经过视图时更改光标,但我想我没有正确编码,因为它不工作 我有一个appcontroller类,在它的.m文件中有这个 - (void) awakeFromNib { //set up the cursors NSCursor * handCursor = [NSCursor closedHandCursor]; //make a box Box* newBox = [[Box alloc] initWithFrame:NSMake
- (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];
}
您忘记调用
[handcursorsetonmouseintered:YES]
。否则,NSCursor
将忽略它发送的mouseenterned:
事件。您忘记调用[handCursor setonmouseintered:YES]
。否则,NSCursor
将忽略它发送的mouseenterned:
事件。从awakeFromNib内调用addCursorRect:。必须从resetCursorRects:的重写中调用它,该重写可能在某个点被调用并关闭设置的rect。从awakeFromNib中调用addCursorRect:将不起作用。必须从resetCursorRects:的重写中调用它,该重写可能会在某个点被调用,并破坏设置的rect