For the More Curious: Rollovers

Three mouse event methods were not discussed in Chapter 18: mouseMoved(_:), mouseEntered(_:), and mouseExited(_:).

To receive mouseMoved(_:), the view’s window needs to accept mouse moved events. If it does, the mouseMoved(_:) message is sent to the window’s first responder. To set the window to get mouse moved events, set the acceptsMouseMovedEvents property to true:

w​i​n​d​o​w​?​.​a​c​c​e​p​t​s​M​o​u​s​e​M​o​v​e​d​E​v​e​n​t​s​ ​=​ ​t​r​u​e​

At this point, the view will be sent the message every time the mouse moves. This is a lot of events. When people ask about mouse moved events, we ask them why they want it. They usually say, “Uh, rollovers.”

Rollovers are very popular with hyperlinks. As ...

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.