Objective-C 中如何改变鼠标光标
我正在制作一个图像编辑应用程序,但如果没有像 Photoshop 中的画笔那样的光标,它看起来非常不完整。如何设置图标,并在退出应用程序时将其更改回来?
这是我的头文件中的代码(以防万一需要):
@interface test : NSWindow <NSWindowDelegate> {
IBOutlet id myView;
}
@end
myView 是一个 NSView
(customView),它将显示所有内容。
I am making an image editing application, but it looks very incomplete without a cursor like they have in Photoshop for the paintbrush. How can I set the icon, and have it change back when I exit the application?
This is the code in my header file (just in case it's needed):
@interface test : NSWindow <NSWindowDelegate> {
IBOutlet id myView;
}
@end
myView is an NSView
(customView) that will display everything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个方便的
NSCursor
类用于处理光标外观。如果其中一个内置光标看起来不符合您的需要,您可以使用NSImage
和-set
初始化一个新的NSCursor
> 它是活动光标。There's a handy
NSCursor
class for handling cursor appearance. If one of the built-in cursors doesn't look how you need it to, you can initialize a newNSCursor
with anNSImage
and-set
it to be the active cursor.如果绘图区域是矩形(NSTracking 区域始终是矩形):-
使用 NSTrackingArea 的 mouseEntered、mouse Exited 方法来跟踪和更改鼠标光标。可以使用 NSCursor 类来更改鼠标光标。
如果跟踪区域不是矩形,则创建一个包含整个绘图区域的更大的矩形跟踪区域,然后跟踪跟踪区域内的 mouseMoved 事件以适当地设置光标。有关更多详细信息,请参阅苹果文档。
If the drawing area is rectangular(NSTracking Areas are always rectangular) :-
Use the mouseEntered,mouse Exited methods of NSTrackingArea to track and change the mouse cursor.The mouse cursor could be changed using NSCursor class.
If the tracking area is not rectangular then make a bigger rectangular tracking area enclosing the whole drawing region and then track the mouseMoved events inside the tracking area to set the cursor appropriately . Refer to apple documentation for more details.