1. Cocoa Keyboard Events
1) Firstly, The view who forwards the event to the key window is pointed by a window outlet called "firstResponder".
可以在interfacebuilder中,手动设置初始化nib时的firstResponder, 并可以通过连接nextKeyView来设置哪个控件为下一个Responder当使用"Tab"健后。 通常,当一个view重写了一个keyDown消息后,keyDown的消息将被该view拥有,也就是说,该view将在执行keyDown函数中的代码而不保留原来预想中的beha
vior,在keyDown中一般使用 [self interpretKeyEvents:[NSArray arrayWithObject: event]],但是在一个customView中需要重写[responderInstance interpretKeyEvents:]中所有用到的函数,详细函数可以在xcode中查到。
2)NSTrackingArea:
An de style="font-size: 11px; font-family: Monaco, Courier, Consolas, monospace; ">NSTrackingAreade> object defines a region of view that generates mouse-tracking and cursor-update events when the mouse is over that region.
改类的解释没有什么可以多说的,就是在view上创建出一个矩形区域来响应一些进入,出去,光标变化等消息。注意,这个area是属于他的view的而不是他的窗口。
With de style="font-size: 11px; font-family: Monaco, Courier, Consolas, monospace; ">NSTrackingAreade>, you can configure the scope of activity for mouse tracking. There are four options:
-
The tracking area is active on
ly when the view is first responder. -
The tracking area is active when the view is in the key window.
-
The tracking area is active when the application is active.
-
The tracking area is active always (even when the application is inactive.
当添加了一个NSTrackingArea后 需要重写mouseEntered: 和mouseExited:这两个method以来设置自己需要做的事情.NSView当然也能remove这样一个area,[viewInstance removeTrackingArea:].