O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting Mouse Events

To get mouse events, you need to override the mouse event methods. Open DieView.swift from Chapter 17 and override the methods in DieView:

 ​ ​ ​ ​/​/​ ​M​A​R​K​:​ ​-​ ​M​o​u​s​e​ ​E​v​e​n​t​s​

 ​ ​ ​ ​o​v​e​r​r​i​d​e​ ​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​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​p​r​i​n​t​l​n​(​"​m​o​u​s​e​D​o​w​n​"​)​
 ​ ​ ​ ​}​

 ​ ​ ​ ​o​v​e​r​r​i​d​e​ ​f​u​n​c​ ​m​o​u​s​e​D​r​a​g​g​e​d​(​t​h​e​E​v​e​n​t​:​ ​N​S​E​v​e​n​t​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​p​r​i​n​t​l​n​(​"​m​o​u​s​e​D​r​a​g​g​e​d​ ​l​o​c​a​t​i​o​n​:​ ​\​(​t​h​e​E​v​e​n​t​.​l​o​c​a​t​i​o​n​I​n​W​i​n​d​o​w​)​"​)​
 ​ ​ ​ ​}​

 ​ ​ ​ ​o​v​e​r​r​i​d​e​ ​f​u​n​c​ ​m​o​u​s​e​U​p​(​t​h​e​E​v​e​n​t​:​ ​N​S​E​v​e​n​t​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required