O'Reilly logo

Cocoa® by Richard Wentk

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

mac_ch16.eps
co_bar.eps

Chapter 16: Managing Views and Creating 2D Graphics

mac_chbox16.eps

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 ...

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