更改特定视图的 NSCursor
我试图在光标经过视图时更改光标,但我想我没有正确编码它,因为它不起作用。
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 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.
您忘记调用
[handCursor setOnMouseEntered:YES]
。否则,NSCursor
将忽略它发送的mouseEntered:
事件。You've forgotten to call
[handCursor setOnMouseEntered:YES]
. Otherwise,NSCursor
will ignore themouseEntered:
event it is sent.