18 Mouse Events

In the previous chapter, you learned to use drawing commands to make a read-only view. A more useful view would be able to accept user input, and what better place to start than handling mouse events?

NSResponder

NSView inherits from NSResponder. All the event-handling methods are declared in NSResponder. We will discuss keyboard events in the next chapter. For now, we will focus on mouse events. NSResponder declares these methods:

 ​ ​ ​ ​f​u​n​c​ ​m​o​u​s​e​D​o​w​n​(​t​h​e​E​v​e​n​t​:​ ​N​S​E​v​e​n​t​)​ ​ ​ ​ ​f​u​n​c​ ​r​i​g​h​t​M​o​u​s​e​D​o​w​n​(​t​h​e​E​v​e​n​t​:​ ​N​S​E​v​e​n​t​)​ ​ ​ ​ ​f​u​n​c​ ​o​t​h​e​r​M​o​u​s​e​D​o​w​n​(​t​h​e​E​v​e​n​t​:​ ​N​S​E​v​e​n​t​)​ ​ ​ ​ ​f​u​n​c​ ​m​o​u​s​e​U​p​(​t​h​e​E​v​e​n​t​:​ ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.