Sharing drawing code between UIViews and NSViews

Since you can use Quartz to draw views in the iPhone SDK just as nicely as you can on the Mac, one might occasionally want to share some drawing code between iPhone apps and Mac apps.

Unfortunately, UIViews have the origin of their coordinate system in the top-left corner, whereas NSViews have it in the bottom-left corner, which means that Quartz drawing code simply copied between the two frameworks will produce horizontally mirrored output on one device.

However, NSView has a method isFlipped that you can override in your subclasses to return YES, which lets Quartz use a coordinate system originating from the top-left corner rather than the default, bottom-left.

So, if you want to share Quartz drawing code between iPhone and Mac apps, be sure to add the following method to your NSView subclasses on the Mac to use the same top-left originating coordinate system on both Mac and iPhone.

- (BOOL)isFlipped
{
    return YES;
}