NSCursor set命令最简单的使用
我正在尝试为我的 OSX 应用程序获取自定义光标。在过去的几个小时里,我读到过有关这样做但没有成功的信息。因此,我已经转向最简单的方面,只需在一个完全没有其他内容的项目中将当前光标设置为十字准线光标。
这是最基本的设置,不会改变我的光标。使用 XCode,我创建了一个新的 Cocoa 项目。我编写的唯一代码是以下函数中的一行。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NSCursor crosshairCursor] set];
}
这不会改变光标,这可能意味着我错过了一些非常基本的东西,但我一生都无法弄清楚。
我尝试了很多变体,使用 NSCursor -push 方法来更改当前光标,但它不起作用。我还尝试放置一个 NSButton,然后按照不同的答案建议此处< /a> (其中按钮的类型为 NSButton *):
[button addCursorRect:[button bounds] cursor:[NSCursor crosshairCursor]];
我之前为 iPhone 编写过几个应用程序,但从未为 Mac 编写过,但看起来非常相似。我错过了一些无可救药的愚蠢的事情吗?我还尝试使用 addCursorRect:cursor: 方法,但我不确定我是否做得对。目前尚不清楚哪个函数应该调用它以及从哪里调用它。
一旦我弄清楚如何显示任何不同的光标,那么我想继续为光标制作自己的图像。
谢谢!
I am trying to get a custom cursor for my OSX application. I've read about doing this without success for the last few hours. So i've moved to the simplest aspect, simply setting the current cursor as the crosshair cursor, in a project that has absolutely nothing else.
Here is the most basic setup which does not change the cursor for me. Using XCode, I made a new Cocoa project. The only piece of code I wrote is one single line in the following function.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NSCursor crosshairCursor] set];
}
This does not change the cursor, which probably means I am missing something extremely basic, but cannot figure out for the life of me.
I tried many variations, using the NSCursor -push method to change the current cursor, and it does not work. I also tried putting an NSButton and then doing as a different answer suggests here (where button is of the type NSButton *):
[button addCursorRect:[button bounds] cursor:[NSCursor crosshairCursor]];
I've written a couple apps for the iPhone before, but never for the Mac, but it seems pretty similar. Am I missing something hopelessly stupid? I also tried playing with the addCursorRect:cursor: method, but I'm not sure I did it right. It wasn't clear what function is supposed to call it, and from where.
Once I figure out how to show ANY different cursor, then I want to move on to making my own images for the cursor.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道为什么,但在 applicationDidFinishLaunching 中设置光标似乎不起作用。 (我刚刚尝试过。)但是如果您稍后执行它,它就会起作用,例如单击按钮的结果,或者如果您希望它在启动时发生,则可以使用计时器。
I'm not sure why, but setting the cursor in applicationDidFinishLaunching doesn't seem to work. (I just tried it.) But it will work if you do it later, like as the result of clicking a button or maybe use a timer if you want it to happen at launch.