Chapter 16: Managing Views and Creating 2D Graphics


In This Chapter

Understanding the view hierarchy

Handling mouse events

Understanding geometry in Cocoa graphics

Creating and drawing paths

Using CoreImage filters

Cocoa and Cocoa Touch have impressive graphics capabilities, but from a developer's point of view, the graphics frameworks are a maze of semicompatible technologies with inconsistent interfaces. The designers of each framework have reinvented fundamental concepts, such as size, position, and orientation, and packed them into incompatible data structures.

One of the most frustrating challenges in graphics programming is the almost constant need to move data between objects and data structures that should be “toll-free bridged,” but aren't.

For example, Cocoa's NSRect and Core Graphics' CGRect structures define a rectangle with identical components: an origin, a width, and a height. In spite of the similarities, you can only move data between them by calling a pair of conversion functions: NSRectToCGRect and NSRectFromCGRect.

Similarly, NSPoint and CGPoint — two data structures that define an x, y coordinate — are incompatible, even though the only difference between ...

Get Cocoa® now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.