NSImage 鼠标事件
我有许多在自定义 NSView 子类中渲染的 NSImage。当用户将鼠标放在这些图像上时,我希望放大这些图像,并且想知道执行此操作的最佳方法。
目前我正在使用 NSView 的 drawRect: 方法来合成图像,但也可以通过 NSImageView 实例自由渲染它们,如果这会让事情变得更容易的话。我最初的本能是为每个 NSImage 实例设置 NSTrackingArea,但想确保我没有遗漏一些明显的东西。
I have a number of NSImages that I'm rendering in a custom NSView subclass. I'm looking to enlarge theses images as and when the user places their mouse over them and am wondering about the best way to go about doing this.
Currently I'm using the NSView's drawRect: method to composite the images, but also free to render them via NSImageView instances, if that will make things easier. My initial instinct was to setup NSTrackingArea's for each NSImage instance but wanted to ensure I wasn't missing something obvious.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能更好的方法是将图像设置为核心动画层。然后,您可以非常轻松地以动画方式弹出/放大图像,而无需编写绘图代码来执行此操作。性能也会好很多。
至于鼠标跟踪,
NSTrackingArea
是一个不错的选择。Possibly a better way to do this would be to set up the images as Core Animation layers. You can then very easily make the images pop up/enlarge in an animated fashion without having to write the drawing code to do it. Performance will be a lot better also.
As for the mouse tracking,
NSTrackingArea
is a good way to go.