可可nsview更改光标

编程入门 行业动态 更新时间:2024-10-24 01:58:44
本文介绍了可可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更改光标

本文发布于:2023-07-31 07:30:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1256740.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:光标   可可   nsview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!