可可nsview更改光标 [英] Cocoa nsview change cursor
本文介绍了可可nsview更改光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试更改可可应用程序中的默认光标.我读到了有关此内容的信息,但标准方法对我不起作用.
I tried to change the default cursor in my cocoa application. I read about this but the standard approach isn't working for me.
我尝试将这种方法添加到我的OpenGLView子类中:
I try to add to my OpenGLView subclass this method:
- (void) resetCursorRects
{
[super resetCursorRects];
NSCursor * myCur = [[NSCursor alloc] initWithImage:[NSImage imageNamed:@"1.png"] hotSpot:NSMakePoint(8,0)];
[self addCursorRect: [self bounds]
cursor: myCur];
NSLog(@"Reset cursor rect!");
}
它不起作用.为什么?
推荐答案
您可以通过两种方式进行操作.首先-最简单-是在鼠标进入视图并离开视图时更改光标.
There're two ways you can do it. First - the most simple - is to change the cursor while the mouse enters the view and leaves it.
- (void)mouseEntered:(NSEvent *)event
{
[super mouseEntered:event];
[[NSCursor pointingHandCursor] set];
}
- (void)mouseExited:(NSEvent *)event
{
[super mouseExited:event];
[[NSCursor arrowCursor] set];
}
另一种方法是创建跟踪区域(即在awakeFromNib
方法中),并覆盖- (void)cursorUpdate:
-方法
Another way is to create tracking area (i.e. in awakeFromNib
-method), and override - (void)cursorUpdate:
-method
- (void)createTrackingArea
{
NSTrackingAreaOptions options = NSTrackingInVisibleRect | NSTrackingCursorUpdate;
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:self.bounds options:options owner:self userInfo:nil];
[self addTrackingArea:area];
}
- (void)cursorUpdate:(NSEvent *)event
{
[[NSCursor pointingHandCursor] set];
}
这篇关于可可nsview更改光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文