NSView子类中的鼠标单击事件 [英] mouse click events in an NSView subclass

查看:514
本文介绍了NSView子类中的鼠标单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用OpenGL上下文初始化的NSView子类,并且具有大量鼠标事件处理(onMouseDown等).我有一个使用它的应用程序,该应用程序具有一个包含视图的可可主窗口,并且所有鼠标事件均正常工作.

I have an NSView subclass that gets initialized with an OpenGL context and has a bunch of mouse event handling (onMouseDown, etc...). I have an app using it which has a main Cocoa window that contains the view and all the mouse events are working properly.

但是,我现在尝试在另一个应用程序中使用它,在该应用程序中,我有一个辅助窗口弹出并用视图初始化,并且当我将鼠标移动到evets时,我似乎没有任何鼠标单击(或键盘)事件.

However, I'm trying to use it now in another app where i have a secondary window that pops open and gets initialized with the view and while i get mouse moved evets, I don't seem to get any mouse click (or keyboard for that matter) events whatsoever.

当我单击并拖动视图时,整个窗口都会移动,我想这是为什么我没有得到任何鼠标事件的原因.我有acceptsFirstResponder和acceptsFirstMouse返回YES,甚至有hitTest返回self来获得良好的测量结果.

When I click and drag on the view, the entire window moves, which im guessing has to do why i dont get any mouse events. I have acceptsFirstResponder and acceptsFirstMouse returning YES and even have hitTest returning self for good measure.

你们有什么主意吗?

推荐答案

您需要从NSView子类中的-mouseDownCanMoveWindow返回NO.

You need to return NO from -mouseDownCanMoveWindow in your NSView subclass.

这篇关于NSView子类中的鼠标单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆