如何检测对任何窗口标题栏的点击?
我想检测 NSWindow 上的鼠标向下移动。事实上,我希望通过检测任何 NSWindow 标题栏上的点击来向整个系统添加功能。但是,我没有看到对 NSWindow 中标题栏或镶边等任何内容的访问。我想我可以监听任何点击并进行数学计算,以根据窗口的大小和位置检测点击是否在标题栏中,但我想知道是否有更好的方法。谢谢!
I would like to detect a mouse down-up on an NSWindow. In fact, I'm looking to add functionality to the system as a whole by detecting a click on any NSWindow's title bar. However, I do not see access to anything like the title bar or chrome in an NSWindow. I suppose I could listen for any click and do the math to detect if the click was within the title bar based on the size and location of the window, but I wanted to know if there was a better way. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要监听窗口框架上的 mouseDown 事件。窗口的框架隐藏在[[window contentView] superview]下。您可以继承 NSWindow 并创建您自己的框架 NSView 的实现(我认为这有点工作),或者尝试用您自己的方法替换 mouseDown 方法。在这里 http://parmanoir.com/Custom_NSThemeFrame 展示了如何为 drawRect 方法执行类似的操作。希望有帮助。
You need to listen to mouseDown events on window's frame. Window's frame is hidden under [[window contentView] superview]. You could either subclass NSWindow and create your own implementation of frame's NSView (I think it' a bit of work) or try to replace just the mouseDown method with your own. In here http://parmanoir.com/Custom_NSThemeFrame it is shown how you can do something like this for drawRect method. Hope it helps.