本文介绍了如果从子视图中拖动,NSView会丢失mouseMoved / mouseDragged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A =父级NSView;
B =子NSView;

A = the parent NSView;B = the child NSView;

B的NSTrackingArea很小;
B是A的一个小子视图;

B has a small NSTrackingArea;B is a small subview of A;

如果移动,单击并拖动到空白区域,则A会正确接收mouseMoved和mouseDragged事件。

A correctly receives mouseMoved and mouseDragged events if moved,clicked, dragged in a empty area.

如果我单击B并将鼠标拖动到其边界之外,则A不会收到任何mouseMoved或mouseDragged事件。

If i click in B and drag the mouse outside of its bounds into A, A does not receive any mouseMoved or mouseDragged events.

有人可以指出我要如何使超级视图A对这种拖曳做出反应吗?

Can someone point me to what i could do to get the superview A to react to this drag?

推荐答案

我观察到


  1. 创建一个NSViewController并将viewA设置为其 view属性。
  1. Create a NSViewController and set viewA as its "view" property.
  2. In my case, I implemented mouseDragged in the view-controller butyou can try on the view and see what results you get. mouseEnteredand mouseExited were implemented in the view subclass.

提示:请确保将跟踪区域边界更新为需要。
希望这会有所帮助。

Tip: Make sure you're updating the tracking area bounds as needed.Hope this helps.

这篇关于如果从子视图中拖动,NSView会丢失mouseMoved / mouseDragged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 13:41